-
Notifications
You must be signed in to change notification settings - Fork 229
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
Table Requirements Validation #200
Conversation
@@ -34,6 +34,10 @@ def __repr__(self) -> str: | |||
"""Return the string representation of the SnapshotRefType class.""" | |||
return f"SnapshotRefType.{self.name}" | |||
|
|||
def __str__(self) -> str: | |||
"""Return the string representation of the SnapshotRefType class.""" | |||
return self.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems we need this __str__
. Otherwise,
>>> ref_type=SnapshotRefType.Branch
>>> f"Test: {ref_type}"
will show Test: SnapshotRefType.Branch
in my local environment (Python 3.11) but Test: branch
in CI's python 3.8. I think it's because Python 3.11 changes the default behavior of Enum's str
: https://blog.pecar.me/python-enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small comments, but looks good 👍
|
||
class AssertCreate(TableRequirement): | ||
"""The table must not already exist; used for create transactions.""" | ||
|
||
type: Literal["assert-create"] = Field(default="assert-create") | ||
|
||
def validate(self, base_metadata: Optional[TableMetadata]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the signature of the parent class as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! I updated the signature and also add None-checks for other requirements, which will raise exception when the current table metadata is None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for working on this @HonahX!
This PR is the second part of #140
It implements a
validate
method for each table requirement. This method raises aCommitFailedException
with an appropriate error message if the table's metadata does not meet the requirements.