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

Change Validations to be Generic #75

Merged
merged 11 commits into from
May 31, 2023
Merged

Conversation

plypaul
Copy link
Contributor

@plypaul plypaul commented May 30, 2023

Resolves #20

Description

This PR changes the signature of the classes used for validation to be generic so that other implementations of the SemanticManifest can use the same framework with type-safety.

Checklist

@cla-bot cla-bot bot added the cla:yes label May 30, 2023
@plypaul plypaul marked this pull request as ready for review May 30, 2023 16:53
Copy link
Collaborator

@tlento tlento left a comment

Choose a reason for hiding this comment

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

Nice, thanks! The pickling dependency could be an issue at some point but we have options for dealing with it if it causes problems, so let us proceed.

Comment on lines 389 to 398
def validate_model_serialized_for_multiprocessing(cls, serialized_model: str) -> str:
"""Validate a model serialized via Pydantic's .json() method, and return a list of JSON serialized issues.

This method exists because our validations are forked into parallel processes via
multiprocessing.ProcessPoolExecutor, and passing a model or validation results object can result in
idiosyncratic behavior and inscrutable errors due to interactions between pickling and pydantic objects.
"""
return SemanticManifestValidationResults.from_issues_sequence(
cls.validate_model(SemanticManifest.parse_raw(serialized_model))
).json()
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I remember correctly this sometimes but not always threw errors. Like I had persistent failures in CI but not locally or vice-versa when this popped up. It's possible pydantic fixed something, or that we cut out the bits that were causing problems (like the special input handing in our old WhereClauseConstraint objects), but it's also possible we just haven't stumbled in a bad configuration yet.

I think it's fine to remove it here, especially given the scope of this PR, but I wouldn't be surprised if we had to put it back. The best practice here is to pass serialized data across the process boundary rather than passing data objects and relying on pickling's best-effort serialization. There's a lot to be said for the key protocols having serialize() and deserialize() or similar methods, which would allow us to avoid the pickling as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got a reproducible failure case, and the issue actually was due to the way that Pydantic handles pickling if there is a dataclass embedded within a Pydantic object. Pickling of the definition Pydantic objects is fine, but pickling of SemanticManifestValidationResults is not, so I changed it to only JSON-serialize that class.

Base automatically changed from plypaul--10.1--change-protocols-to-use-abstract-property to main May 30, 2023 23:55
@plypaul plypaul merged commit f78749b into main May 31, 2023
14 checks passed
@plypaul plypaul deleted the plypaul--10.2--generic-validations branch May 31, 2023 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update SemanticManifestValidator to expect a generic bound by the SemanticManifest Protocol
2 participants