forked from python-attrs/attrs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clear cache hash on de-serialization (python-attrs#489)
* Don't cache hash codes across deserialization. Because the hash code cache field gets serialized and deserialized by Pickle, previously when you deserialize a cache_hash=True attrs object, the hashcode will be the hashcode the object had at serialization-time. However, if your object had fields with hash codes which were not deterministic between interpreter runs, then on a new interpreter run your deserialized object would have a hash code which differs from a newly created identical object. This commit fixes that by clearing the cache on deserialization. It needs to override the __setstate__ method to do so, so this commit also forbids using a custom __setstate__ on a cache_hash=True object. Closes python-attrs#482 . * Improve exception type * Minor tweaks to comments formatting * Fix test for Python 2.7 * Fix error in comment * Make nomenclature consistent for slotted/dict classes * Remove hasattr() * Improve comments and error message for custom __setstate__ + cache_hash=True * Drop use of for test classes for cache hash serialization * Make changelog note this is a breaking change * Make exception message point to tracking issue * Fix test classes for Python 2.7
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Fixed a bug where deserialized objects with ``cache_hash=True`` could have incorrect hash code values. | ||
This change breaks classes with ``cache_hash=True`` when a custom ``__setstate__`` is present. | ||
An exception will be thrown when applying the ``attrs`` annotation to such a class. | ||
This limitation is tracked in issue https://github.com/python-attrs/attrs/issues/494 . |
This file contains 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
This file contains 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