Remove validity check for csv writer and make csv writing more defensive#222
Remove validity check for csv writer and make csv writing more defensive#222codycooperross merged 2 commits intomasterfrom
Conversation
📝 WalkthroughWalkthroughThis PR increments the version number from 2.5.1 to 2.5.2 and refactors the CSV writer method to remove an early validation return, replacing it with conditional guards for accessing nested fields using Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 RuboCop (1.85.0)lib/bolognese/version.rbrubocop-rails extension supports plugin, specify lib/bolognese/writers/csv_writer.rbrubocop-rails extension supports plugin, specify Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/bolognese/writers/csv_writer.rb (1)
6-21:⚠️ Potential issue | 🟡 MinorConsider adding a validity check for consistency with other export methods.
The
csvmethod lacks the validity check present inbibtex(which returnsnilunlessvalid?) andcodemeta(which returnsnilunlessvalid?orshow_errors). This creates an inconsistent API wherecsvalways returns a CSV string regardless of validity, while similar export methods protect against exporting invalid metadata.If this inconsistency is intentional, document why CSV exports should differ from other formats. Otherwise, align the implementation with other writers by adding an early validity check.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/bolognese/writers/csv_writer.rb` around lines 6 - 21, The csv method should enforce the same validity guard as the other exporters: add an early check in csv (the method in lib/bolognese/writers/csv_writer.rb) to return nil when the metadata is invalid, mirroring bibtex (i.e. return nil unless valid?) or, if you want parity with codemeta behavior, use the same condition (return nil unless valid? || show_errors) so CSV exports are consistent with the bibtex/codemeta writers; place this check at the top of the csv method before building the bib array.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@lib/bolognese/writers/csv_writer.rb`:
- Around line 6-21: The csv method should enforce the same validity guard as the
other exporters: add an early check in csv (the method in
lib/bolognese/writers/csv_writer.rb) to return nil when the metadata is invalid,
mirroring bibtex (i.e. return nil unless valid?) or, if you want parity with
codemeta behavior, use the same condition (return nil unless valid? ||
show_errors) so CSV exports are consistent with the bibtex/codemeta writers;
place this check at the top of the csv method before building the bib array.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7aa40e74-ed70-48a8-af39-6efa12b49d21
⛔ Files ignored due to path filters (1)
Gemfile.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
lib/bolognese/version.rblib/bolognese/writers/csv_writer.rb
Purpose
When csv format is requested in lupo, the operation will silently return nil unless the ActiveRecord Doi object is valid. The Doi object may be invalid for reasons beyond metadata, including a mismatch between the Doi object's url and the allowed domains by its parent client. Consequently, lupo-generated CSV output may contain missing lines for "invalid" records even though these should be represented. This PR removes the validity check, which seems unnecessary, and adds several defensive measures to avoid errors during csv generation.
Part of: datacite/datacite#2502
Approach
Open Questions and Pre-Merge TODOs
Learning
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Reviewer, please remember our guidelines:
Summary by CodeRabbit
Release Notes
Bug Fixes
Chores