Skip to content

rows_from_file() honours ignore_extras= and extras_key= for TSV and auto-detect - #973

Merged
simonw merged 1 commit into
mainfrom
rows-from-file-extras
Nov 29, 2026
Merged

simonw merged 1 commit into
mainfrom
rows-from-file-extras

Conversation

@simonw

@simonw simonw commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Fixes:

rows_from_file() ignored ignore_extras= and extras_key= for TSV files and for auto-detected CSV/TSV, raising RowError even when the caller asked for extra values to be ignored or collected.

Claude Fable 5.2 Medium
rows, _ = rows_from_file(
    BytesIO(b"id\tname\r\n1\tCleo\toops"), format=Format.TSV, ignore_extras=True
)
list(rows)

Current buggy behavior produces:

sqlite_utils.utils.RowError: Row {'id': '1', 'name': 'Cleo'} contained these extra values: ['oops']

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.

  • Both branches now pass ignore_extras= and extras_key= to the inner call.
  • The two outer _extra_key_strategy() wrappers are removed, so extras are handled once, on the CSV path.

What is unchanged

  • With neither option, CSV, TSV and auto-detected files all still raise RowError.
  • Passing both options together still raises ValueError, for every format.
  • JSON and newline-delimited JSON still ignore either option on its own. A test pins that.
  • sqlite-utils memory is the only caller in the package and passes neither option, so the CLI behaves as before. insert --csv has 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.py cover explicit CSV, explicit TSV and auto-detected CSV/TSV against the default, ignore_extras and extras_key. 6 of them fail on main and pass here. Full suite: 1603 passed, 4 skipped.

🤖 Generated with Claude Code


📚 Documentation preview 📚: https://sqlite-utils--973.org.readthedocs.build/en/973/

…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

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.80%. Comparing base (1c271c3) to head (204003f).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@simonw simonw added the bug Something isn't working label Nov 29, 2026
@simonw
simonw merged commit f5bd18a into main Nov 29, 2026
83 checks passed
simonw added a commit that referenced this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant