Repository navigation
Raise for an explicit snapshot_id=0 in inspect.files() on a table without snapshots - #4620
shashank11yadav wants to merge 2 commits into
Conversation
…hout snapshots 0 was treated as "no snapshot id", so the empty-table shortcut hid an unknown id. Use `is None`, as `_get_snapshot` does.
Fokko
left a comment
There was a problem hiding this comment.
Thanks @shashank11yadav! Nice catch, and good regression test that fails without the fix. Verified locally that the new test fails on the pre-fix code and passes with it, and the full tests/table/test_inspect.py suite is green. Same truthiness mistake that #3998 fixed for scans, so this closes the loop on #4619.
Two nits, both non-blocking:
tests/table/test_inspect.py:313: could you use@pytest.mark.parametrizehere instead of a loop?pyiceberg/table/inspect.py:886: the_filesdocstring does not mention that an explicit unknownsnapshot_idraisesValueError, unlikeentriesatpyiceberg/table/inspect.py:166. Maybe a shortRaises:block there?
| def test_inspect_files_with_snapshot_id_zero_on_table_without_snapshots(catalog: InMemoryCatalog) -> None: | ||
| tbl = catalog.create_table("default.no_snapshots", Schema(NestedField(1, "x", LongType(), required=False))) | ||
|
|
||
| for inspect_files in [tbl.inspect.files, tbl.inspect.data_files, tbl.inspect.delete_files]: | ||
| assert inspect_files().num_rows == 0 | ||
| with pytest.raises(ValueError, match="Cannot find snapshot with ID 0"): | ||
| inspect_files(snapshot_id=0) |
There was a problem hiding this comment.
Nit: could you use @pytest.mark.parametrize here instead of a loop?
| def test_inspect_files_with_snapshot_id_zero_on_table_without_snapshots(catalog: InMemoryCatalog) -> None: | |
| tbl = catalog.create_table("default.no_snapshots", Schema(NestedField(1, "x", LongType(), required=False))) | |
| for inspect_files in [tbl.inspect.files, tbl.inspect.data_files, tbl.inspect.delete_files]: | |
| assert inspect_files().num_rows == 0 | |
| with pytest.raises(ValueError, match="Cannot find snapshot with ID 0"): | |
| inspect_files(snapshot_id=0) | |
| @pytest.mark.parametrize("inspect_files", [InspectTable.files.fget, InspectTable.data_files.fget, InspectTable.delete_files.fget]) | |
| def test_inspect_files_with_snapshot_id_zero_on_table_without_snapshots( | |
| catalog: InMemoryCatalog, inspect_files | |
| ) -> None: | |
| tbl = catalog.create_table("default.no_snapshots", Schema(NestedField(1, "x", LongType(), required=False))) | |
| assert inspect_files(tbl).num_rows == 0 | |
| with pytest.raises(ValueError, match="Cannot find snapshot with ID 0"): | |
| inspect_files(tbl, snapshot_id=0) |
There was a problem hiding this comment.
Done in 342f45b. I parametrized over the method names and call getattr(tbl.inspect, method), the same way test_inspect_files_of_snapshot_without_manifests does, instead of using the suggestion as written: files, data_files and delete_files are plain methods rather than properties, so .fget isn't there, and they need tbl.inspect as self, not tbl. It's now three cases, [files], [data_files] and [delete_files], and all three fail without the fix.
…r in _files Split the test over files, data_files and delete_files with pytest.mark.parametrize, as test_inspect_files_of_snapshot_without_manifests does, and add a Raises section to the _files docstring.
Thanks for the review. I added a |
Fixes #4619
Rationale for this change
InspectTable._filescheckedif not snapshot_id and ..., so an explicitsnapshot_id=0was treated the same as "no snapshot id". On a table with no snapshots,files(),data_files()anddelete_files()then returned an empty table forsnapshot_id=0, instead of raisingValueError: Cannot find snapshot with ID 0as every other unknown id does.The fix checks
snapshot_id is None, as_get_snapshotalready does. Calls without asnapshot_idstill return an empty table on a table without snapshots, as the method docstring describes.Are these changes tested?
Yes. One new test,
test_inspect_files_with_snapshot_id_zero_on_table_without_snapshots, intests/table/test_inspect.py. For all three methods it checks that the default call returns no rows and thatsnapshot_id=0raisesValueError.The new test fails without the fix.
With the fix applied, the new test passes.
Local results on this commit:
tests/table/test_inspect.pyfile, with the unit marker: pass.pyicebergandtests: pass.make lint(the full pre-commit hook set) was not run, so the lint result above covers only ruff.Are there any user-facing changes?
Yes, a behaviour change. An explicit
snapshot_id=0on a table with no snapshots now raisesValueErrorininspect.files(),data_files()anddelete_files(). Before, it returned an empty table. Calls without asnapshot_idare unchanged, and no other call path changes.Please add the
changeloglabel, since this changes behaviour.