Repository navigation
rows_from_file() honours ignore_extras= and extras_key= for TSV and auto-detect - #973
Merged
Merged
Conversation
…uto-detect The TSV branch and the format-detection branch both recursed into the CSV branch without forwarding ignore_extras= or extras_key=, so the inner call used its defaults and raised RowError before the outer _extra_key_strategy() wrapper ever saw the row. Forward both arguments and drop the outer wrappers, which were dead code, so extras are handled exactly once on the shared CSV path. Tests now cover explicit CSV, explicit TSV and auto-detected CSV/TSV with the default, ignore_extras=True and extras_key=, plus the both-options ValueError and the no-op behaviour for JSON/NL. Refs #892 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #973 +/- ##
==========================================
+ Coverage 94.78% 94.80% +0.02%
==========================================
Files 10 10
Lines 4585 4585
==========================================
+ Hits 4346 4347 +1
+ Misses 239 238 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes:
rows_from_file()ignoredignore_extras=andextras_key=for TSV files and for auto-detected CSV/TSV, raisingRowErroreven when the caller asked for extra values to be ignored or collected.Claude Fable 5.2 Medium
Current buggy behavior produces:
With this fix applied you get:
[{'id': '1', 'name': 'Cleo'}]And with
extras_key="_rest":[{'id': '1', 'name': 'Cleo', '_rest': ['oops']}].The change
The TSV branch and the auto-detect branch both call
rows_from_file(..., format=Format.CSV)recursively, but did not pass the two options on. The inner call used its defaults and raised before the outer_extra_key_strategy()wrapper saw the row, so that wrapper was dead code.ignore_extras=andextras_key=to the inner call._extra_key_strategy()wrappers are removed, so extras are handled once, on the CSV path.What is unchanged
RowError.ValueError, for every format.sqlite-utils memoryis the only caller in the package and passes neither option, so the CLI behaves as before.insert --csvhas its own reader and is not touched (insert --csv drops values past the header, rows_from_file raises for the same input #890).For TSV and auto-detected input the returned rows object is now the same closeable iterator explicit CSV already returned, instead of a generator wrapping it.
Testing
New tests in
tests/test_rows_from_file.pycover explicit CSV, explicit TSV and auto-detected CSV/TSV against the default,ignore_extrasandextras_key. 6 of them fail onmainand pass here. Full suite: 1603 passed, 4 skipped.🤖 Generated with Claude Code
📚 Documentation preview 📚: https://sqlite-utils--973.org.readthedocs.build/en/973/