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)):
|
491 | 491 | need to do things manually, as they're dynamically created classes and |
492 | 492 | only module-level classes can be pickled by the default path. |
493 | 493 | """ |
494 | | data = self.__dict__ |
495 | | data[DJANGO_VERSION_PICKLE_KEY] = get_version() |
| 494 | pickled_version = get_version() |
496 | 495 | if not self._deferred: |
497 | 496 | 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__ |
499 | 498 | defers = [] |
500 | 499 | for field in self._meta.fields: |
501 | 500 | if isinstance(self.__class__.__dict__.get(field.attname), |
… |
… |
class Model(six.with_metaclass(ModelBase)):
|
503 | 502 | defers.append(field.attname) |
504 | 503 | model = self._meta.proxy_for_model |
505 | 504 | 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__) |
524 | 506 | |
525 | 507 | def _get_pk_val(self, meta=None): |
526 | 508 | if not meta: |
… |
… |
def simple_class_factory(model, attrs):
|
1689 | 1671 | return model |
1690 | 1672 | |
1691 | 1673 | |
1692 | | def model_unpickle(model_id, attrs, factory): |
| 1674 | def model_unpickle(model_id, attrs, factory, pickled_version=None): |
1693 | 1675 | """ |
1694 | 1676 | Used to unpickle Model subclasses with deferred fields. |
1695 | 1677 | """ |
| 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 | |
1696 | 1691 | if isinstance(model_id, tuple): |
1697 | 1692 | if not apps.ready: |
1698 | 1693 | apps.populate(settings.INSTALLED_APPS) |