Add serializer for AssertRefSnapshotId allowing null json value#2375
Merged
kevinjqliu merged 8 commits intoapache:mainfrom Aug 25, 2025
Merged
Add serializer for AssertRefSnapshotId allowing null json value#2375kevinjqliu merged 8 commits intoapache:mainfrom
kevinjqliu merged 8 commits intoapache:mainfrom
Conversation
3 tasks
kevinjqliu
approved these changes
Aug 22, 2025
Contributor
kevinjqliu
left a comment
There was a problem hiding this comment.
LGTM! slight nit on making a few changes for maintainability :)
pyiceberg/table/update/__init__.py
Outdated
Comment on lines
732
to
736
| return { | ||
| "type": self.type, | ||
| "ref": self.ref, | ||
| "snapshot-id": self.snapshot_id, | ||
| } |
Contributor
There was a problem hiding this comment.
nit: is there a way to call super() or the default serializer? we just want to explicitly override for snapshot-id.
otherwise, we'd have to remember to change to this function everytime we add a new variable
Contributor
Author
There was a problem hiding this comment.
yes! Added the mode='wrap' param that allows that
kevinjqliu
approved these changes
Aug 25, 2025
kevinjqliu
reviewed
Aug 25, 2025
Contributor
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.
Closes #2342
Rationale for this change
The last attempt at fixing this (#2343) did not actually end up serializing None values to
null. This was b/c theAssertRefSnapshotIdrequirement was often a child object of some otherRequestobject, which was actually getting themodel_dump_json()call. This meant that theexclude_none=Trueoverride would remove anyNones before any of theField-specific configurations would be considered (likeexclude=Falseor the model's ownmodel_dump_jsonmethod).I then investigated setting some
ConfigDictsettings on the model, but that also did not have any useful configurations.I looked into setting
exclude_none=Trueat all of themodel_json_dump()callsites but there were too many and it would be easy to forget to set that value every time. The issue is that many values are supposed to be absent to instruct the REST Catalog about what the client wants (things like filtering, for instance).The solution I ended up with was allowingsnapshot_idto be a requiredintwith a default value of-1, and adding a json-specific field serializer to write outnullwhen dumping to json. This seems to workThe solution that worked and allowed for
snapshot_idto be set toNone(as it's done in Ray Data), was to define amodel_serializermethod and always return the fields. This was based on conversations in pydantic/pydantic#7326.Are these changes tested?
Yes
Are there any user-facing changes?
Actually allow
snapshot-idto be null forassert-ref-snapshot-idrequirements