Skip to content

Commit f4e27bd

Browse files
committed
Fix integration test todict for DataFile's V3-only properties
test_rest_manifest.py has its own todict helper (separate from tests/avro/test_file.py's), which also enumerates every DataFile property via reflection. Adding V3-only properties to DataFile in the previous commit caused this helper to include them for a V2-shaped record too, diverging from the V2 dict fastavro writes and failing the REST integration round-trip test.
1 parent a6f00b8 commit f4e27bd

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

tests/integration/test_rest_manifest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@
3333
from pyiceberg.typedef import Record
3434
from pyiceberg.utils.lazydict import LazyDict
3535

36+
# DataFile exposes properties for fields added in newer format versions (e.g. the V3-only
37+
# first_row_id). A record bound to an older layout does not carry those fields in its positional
38+
# data, so they are excluded from the serialized dict to match the fields fastavro writes for that
39+
# layout, keyed by the _data length beyond which each field is absent.
40+
_DATA_FILE_FIELDS_BY_MIN_DATA_LEN = {
41+
"first_row_id": 17,
42+
"referenced_data_file": 18,
43+
"content_offset": 19,
44+
"content_size_in_bytes": 20,
45+
}
46+
3647

3748
# helper function to serialize our objects to dicts to enable
3849
# direct comparison with the dicts returned by fastavro
@@ -49,10 +60,12 @@ def todict(obj: Any, spec_keys: list[str]) -> Any:
4960
elif hasattr(obj, "__iter__") and not isinstance(obj, str) and not isinstance(obj, bytes):
5061
return [todict(v, spec_keys) for v in obj]
5162
elif hasattr(obj, "__dict__"):
63+
min_data_len = _DATA_FILE_FIELDS_BY_MIN_DATA_LEN if isinstance(obj, DataFile) else {}
64+
data_len = len(obj._data)
5265
return {
5366
key: todict(value, spec_keys)
5467
for key, value in inspect.getmembers(obj)
55-
if not callable(value) and not key.startswith("_")
68+
if not callable(value) and not key.startswith("_") and data_len >= min_data_len.get(key, 0)
5669
}
5770
else:
5871
return obj

0 commit comments

Comments
 (0)