Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CommitTableRequest serialisation #525

Merged
merged 8 commits into from
Mar 17, 2024

Conversation

kdbhiggins
Copy link
Contributor

I discovered an error when trying to deserialize the CommitTableRequest object.

  request = CommitTableRequest(
      requirements=(AssertTableUUID(uuid='4bfd18a3-74c6-478e-98b1-71c4c32f4163'),),
      identifier=TableIdentifier(namespace=['a'], name='b'),
  )

  deserialized_request = CommitTableRequest.model_validate_json(request.model_dump_json())

raises
TypeError: Can't instantiate abstract class TableRequirement with abstract method validate

I added a test to round-trip serialize/deserialize the CommitTableRequest. After investigating I was able to fix it by using Discriminated Unions, which seem like a natural fit for the TableUpdate and TableRequirement.

Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @kdbhiggins, and also nice that this gets rid of SerializeAsAny

@Fokko Fokko merged commit a077c73 into apache:main Mar 17, 2024
7 checks passed
@HonahX HonahX added this to the PyIceberg 0.6.1 milestone Mar 26, 2024
Fokko pushed a commit to Fokko/iceberg-python that referenced this pull request Mar 28, 2024
* add failing test

* make requirements a discriminated union

* use discriminated type union

* add return type

* use type annotation

* have requirements inherit from ValidatableTableRequirement

* AddSortOrder filter by type

* lint

---------

Co-authored-by: Kieran Higgins <[email protected]>
Fokko pushed a commit to Fokko/iceberg-python that referenced this pull request Mar 28, 2024
* add failing test

* make requirements a discriminated union

* use discriminated type union

* add return type

* use type annotation

* have requirements inherit from ValidatableTableRequirement

* AddSortOrder filter by type

* lint

---------

Co-authored-by: Kieran Higgins <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants