1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #21430 -- Added a RuntimeWarning when unpickling Models and QuerySets from a different Django version.

Thanks FunkyBob for the suggestion, prasoon2211 for the initial patch,
and akaariai, loic, and charettes for helping in shaping the patch.
This commit is contained in:
Anubhav Joshi
2014-06-06 16:40:20 +05:30
committed by Tim Graham
parent e163a3d17b
commit 42736ac8e8
11 changed files with 210 additions and 16 deletions

View File

@@ -5,10 +5,12 @@ The main QuerySet implementation. This provides the public API for the ORM.
from collections import deque
import copy
import sys
import warnings
from django.conf import settings
from django.core import exceptions
from django.db import connections, router, transaction, IntegrityError
from django.db import (connections, router, transaction, IntegrityError,
DJANGO_VERSION_PICKLE_KEY)
from django.db.models.constants import LOOKUP_SEP
from django.db.models.fields import AutoField, Empty
from django.db.models.query_utils import (Q, select_related_descend,
@@ -19,6 +21,7 @@ from django.db.models import sql
from django.utils.functional import partition
from django.utils import six
from django.utils import timezone
from django.utils.version import get_version
# The maximum number (one less than the max to be precise) of results to fetch
# in a get() query
@@ -90,8 +93,26 @@ class QuerySet(object):
# Force the cache to be fully populated.
self._fetch_all()
obj_dict = self.__dict__.copy()
obj_dict[DJANGO_VERSION_PICKLE_KEY] = get_version()
return obj_dict
def __setstate__(self, state):
msg = None
pickled_version = state.get(DJANGO_VERSION_PICKLE_KEY)
if pickled_version:
current_version = get_version()
if current_version != pickled_version:
msg = ("Pickled queryset instance's Django version %s does"
" not match the current version %s."
% (pickled_version, current_version))
else:
msg = "Pickled queryset instance's Django version is not specified."
if msg:
warnings.warn(msg, RuntimeWarning, stacklevel=2)
self.__dict__.update(state)
def __reduce__(self):
"""
Used by pickle to deal with the types that we create dynamically when