rows_from_file() ignores ignore_extras= and extras_key= for anything that isn't Format.CSV
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
Hướng nghiên cứu
Bắt đầu trong sqlite_utils/utils.py tại rows_from_file() và kiểm tra tests/test_rows_from_file.py, đặc biệt là bài kiểm thử CSV hiện có ở dòng 44. Chạy các bài kiểm thử rows_from_file, sau đó bao phủ các đường dẫn TSV và tự động phát hiện được đề cập rõ ràng, đồng thời giữ nguyên hành vi RowError mặc định. Hoàn thành khi ignore_extras và extras_key hoạt động nhất quán đối với các đường dẫn đó mà không thay đổi giá trị mặc định được ghi chép.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
rows_from_file() ignores ignore_extras= and extras_key= for anything that isn't explicitly format=Format.CSV.
The docstring says:
If a CSV or TSV file includes rows with more fields than are declared in the header a
sqlite_utils.utils.RowErrorexception will be raised when you loop over the generator.You can instead ignore the extra data by passing
ignore_extras=True.Or pass
extras_key="rest"to put those additional values in a list in a key calledrest.
In practice those two options only work for format=Format.CSV. For TSV — which the docstring names explicitly — and for the auto-detected path (format omitted) they are silently discarded, and the caller's own explicit request is contradicted by a RowError.
Both branches that recurse into the CSV branch call rows_from_file() without forwarding the two arguments, so the inner call uses its own defaults (ignore_extras=False, extras_key=None) and raises before the outer _extra_key_strategy() wrapper — which is dead code — ever sees the row:
>>> from io import BytesIO
>>> from sqlite_utils.utils import rows_from_file, Format
>>> rows, _ = rows_from_file(
... BytesIO(b"id\tname\r\n1\tCleo\toops"),
... format=Format.TSV,
... ignore_extras=True,
... )
>>> list(rows)
Traceback (most recent call last):
...
sqlite_utils.utils.RowError: Row {'id': '1', 'name': 'Cleo'} contained these extra values: ['oops']
The same happens with extras_key="_rest":
>>> rows, _ = rows_from_file(
... BytesIO(b"id\tname\r\n1\tCleo\toops"),
... format=Format.TSV,
... extras_key="_rest",
... )
>>> list(rows)
Traceback (most recent call last):
...
sqlite_utils.utils.RowError: Row {'id': '1', 'name': 'Cleo'} contained these extra values: ['oops']
With no options passed the behaviour is correct and should not change — RowError is still raised, as documented.
git log -S"_extra_key_strategy" points at d379f43 ("rows_from_file(... ignore_extras: bool, restkey: str), refs #440"), which introduced the strategy and both branches in one commit. The recursion has never forwarded the arguments, so this looks like an oversight in the original commit rather than a decision.
The existing test hardcoded format=Format.CSV (tests/test_rows_from_file.py:44), which is why it was never caught.
Proposed fix
Forward ignore_extras= and extras_key= to the inner call in both branches, and drop the now-redundant outer _extra_key_strategy wrapper so the strategy is applied once, on the shared CSV path that already implements it.
Note on scope
I would fix the auto-detect branch in the same commit, since it is the same root cause (same dropped-argument recursion, same dead wrapper) and would otherwise be a one-line follow-up. It interacts with #891: once the sniffer picks the right delimiter for a ragged file, the auto-detected path will honour ignore_extras too.
I did not add an auto-detect regression test, because csv.Sniffer returns the wrong delimiter on a small ragged input and pinning today's sniffing behaviour would bake in the bug #891 is about. The TSV test passes an explicit format, so it does not depend on the sniffer.
- Ngôn ngữ chính
- Python
- Star
- 2.2k
- Fork
- 215
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của simonw/sqlite-utils
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
simonw/sqlite-utils#928 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Tests use CliRunner.isolated_filesystem(), which is deprecated and will be removed in Click 9.0Có thể đã có người làm @devpryan7792 đã nhận 11 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
simonw/sqlite-utils#916 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
rows_from_file() splits a single-column CSV file on a letter, or raises csv.ErrorCó thể đã có người làm @L4XB đã nhận 19 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
simonw/sqlite-utils#907 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
enable_fts() exhausts iterator columns before populating the indexCó thể đã có người làm @syahra712 đã nhận 25 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
simonw/sqlite-utils#902 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Raw numpy scalar values get silently stored as corrupted BLOBs instead of being convertedCó thể đã có người làm @TanbirRamim đã nhận 43 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
simonw/sqlite-utils#876 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của simonw/sqlite-utils
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
didi/helixharness#18 ·
-
[MOVIE]: Airport '77 (1977)Đang mởrequest-theme
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
LizardByte/ThemerrDB#9883 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
NousResearch/hermes-agent#149885 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Set cache_ok = True on GUID TypeDecorator to enable SQLAlchemy query cachingCó thể đã có người làm @patelshivani2283-lab đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
fedora-infra/anitya#2157 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Project-MONAI/MONAI#9258 ·
Maintainer thường phản hồi trong vòng 3 ngày