Ticket #25426: patch_25426.diff

File patch_25426.diff, 2.9 KB (added by Iru Hwang, 5 years ago)
  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index be1cb48..4cfd933 100644
    a b class Model(six.with_metaclass(ModelBase)): 
    491491        need to do things manually, as they're dynamically created classes and
    492492        only module-level classes can be pickled by the default path.
    493493        """
    494         data = self.__dict__
    495         data[DJANGO_VERSION_PICKLE_KEY] = get_version()
     494        pickled_version = get_version()
    496495        if not self._deferred:
    497496            class_id = self._meta.app_label, self._meta.object_name
    498             return model_unpickle, (class_id, [], simple_class_factory), data
     497            return model_unpickle, (class_id, [], simple_class_factory, pickled_version), self.__dict__
    499498        defers = []
    500499        for field in self._meta.fields:
    501500            if isinstance(self.__class__.__dict__.get(field.attname),
    class Model(six.with_metaclass(ModelBase)): 
    503502                defers.append(field.attname)
    504503        model = self._meta.proxy_for_model
    505504        class_id = model._meta.app_label, model._meta.object_name
    506         return (model_unpickle, (class_id, defers, deferred_class_factory), data)
    507 
    508     def __setstate__(self, state):
    509         msg = None
    510         pickled_version = state.get(DJANGO_VERSION_PICKLE_KEY)
    511         if pickled_version:
    512             current_version = get_version()
    513             if current_version != pickled_version:
    514                 msg = ("Pickled model instance's Django version %s does"
    515                     " not match the current version %s."
    516                     % (pickled_version, current_version))
    517         else:
    518             msg = "Pickled model instance's Django version is not specified."
    519 
    520         if msg:
    521             warnings.warn(msg, RuntimeWarning, stacklevel=2)
    522 
    523         self.__dict__.update(state)
     505        return (model_unpickle, (class_id, defers, deferred_class_factory, pickled_version), self.__dict__)
    524506
    525507    def _get_pk_val(self, meta=None):
    526508        if not meta:
    def simple_class_factory(model, attrs): 
    16891671    return model
    16901672
    16911673
    1692 def model_unpickle(model_id, attrs, factory):
     1674def model_unpickle(model_id, attrs, factory, pickled_version=None):
    16931675    """
    16941676    Used to unpickle Model subclasses with deferred fields.
    16951677    """
     1678    msg = None
     1679    if pickled_version:
     1680        current_version = get_version()
     1681        if current_version != pickled_version:
     1682            msg = ("Pickled model instance's Django version %s does"
     1683                   " not match the current version %s."
     1684                   % (pickled_version, current_version))
     1685    else:
     1686        msg = "Pickled model instance's Django version is not specified."
     1687
     1688    if msg:
     1689        warnings.warn(msg, RuntimeWarning, stacklevel=2)
     1690
    16961691    if isinstance(model_id, tuple):
    16971692        if not apps.ready:
    16981693            apps.populate(settings.INSTALLED_APPS)
Back to Top