Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix backward compatibility with pickles before v22.2.0
Unfortunately we're using `django-redis` to cache some `attrs` instances and the change to make `__getstate__` and `__setstate__` use `dict` values instead of `tuple` values prevents reading any values from the cache when updating to `attrs>=22.2.0`. We get an `AttributeError` raised for all attributes. This happens because the tuple of values stored in the original pickle is checked for the name of the attribute and so none of the attributes are set on unpickle. To address this I've made a change so that `__setstate__` will still be able to handle values pickled as `tuple`s allowing existing pickles to be unpickled. The test just contains a pre-pickled value due to the complexities around tying to mock methods on a slotted as documented[^1]. I realise that documentation also mentions that we should "think twice" before using pickle, but sometimes those decisions predate our involvement in a project! In addition, pretty much all of Django's cache implementations are built around using pickle by default. This change will allow an easier path to upgrade by unpickling and repickling all values in the cache. Regression in 89a890a. [^1]: https://www.attrs.org/en/latest/glossary.html#term-slotted-classes
- Loading branch information