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

Fix backward compatibility with pickles before v22.2.0 #1085

Merged
merged 3 commits into from
Jan 25, 2023

Commits on Jan 23, 2023

  1. Configuration menu
    Copy the full SHA
    9df9b08 View commit details
    Browse the repository at this point in the history
  2. 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
    ngnpope committed Jan 23, 2023
    Configuration menu
    Copy the full SHA
    1139a3d View commit details
    Browse the repository at this point in the history

Commits on Jan 25, 2023

  1. Update 1085.change.md

    hynek authored Jan 25, 2023
    Configuration menu
    Copy the full SHA
    8eb51fe View commit details
    Browse the repository at this point in the history