fix!: ignore private attributes doing equality pydantic#2035
Merged
Conversation
1185463 to
46eb15a
Compare
izeigerman
reviewed
Jan 30, 2024
izeigerman
approved these changes
Jan 30, 2024
687e755 to
20d64fb
Compare
20d64fb to
12a077b
Compare
12a077b to
e2720c2
Compare
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.
We have an issue that Pydantic includes private attributes in the equality check:
https://github.com/pydantic/pydantic/blob/b785d5b1db4eccb922dd2bf17faea5fc842e6a57/pydantic/main.py#L880
We use these for caching values. When we do equality checks our intent is to check if the public attributes of the class are the same and not if the cached attributes are equal.
This PR has a way of solving this problem but involves mutating the actual objects themselves so it would be best if we had a solution that didn't involve that. Are there Pydantic config properties that can help us here? @izeigerman do you have any ideas? I want to find a solution that works for all Pydantic classes instead requiring each one to provide an override if they introduce private attributes.