Skip to content

Commit

Permalink
[1.1.X] Fixed #12121 -- Modified __reduce__ on a model to avoid an in…
Browse files Browse the repository at this point in the history
…finite recursion problem that occurs on Python 2.4. Thanks to emulbreh for the report.

Backport of r11691 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11692 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
freakboy3742 committed Nov 1, 2009
1 parent 9e02b4a commit fe9a45e
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions django/db/models/base.py
Expand Up @@ -359,20 +359,25 @@ def __reduce__(self):
only module-level classes can be pickled by the default path. only module-level classes can be pickled by the default path.
""" """
data = self.__dict__ data = self.__dict__
if not self._deferred: model = self.__class__
return super(Model, self).__reduce__() # The obvious thing to do here is to invoke super().__reduce__()
# for the non-deferred case. Don't do that.
# On Python 2.4, there is something wierd with __reduce__,
# and as a result, the super call will cause an infinite recursion.
# See #10547 and #12121.
defers = [] defers = []
pk_val = None pk_val = None
for field in self._meta.fields: if self._deferred:
if isinstance(self.__class__.__dict__.get(field.attname), for field in self._meta.fields:
DeferredAttribute): if isinstance(self.__class__.__dict__.get(field.attname),
defers.append(field.attname) DeferredAttribute):
if pk_val is None: defers.append(field.attname)
# The pk_val and model values are the same for all if pk_val is None:
# DeferredAttribute classes, so we only need to do this # The pk_val and model values are the same for all
# once. # DeferredAttribute classes, so we only need to do this
obj = self.__class__.__dict__[field.attname] # once.
model = obj.model_ref() obj = self.__class__.__dict__[field.attname]
model = obj.model_ref()


return (model_unpickle, (model, defers), data) return (model_unpickle, (model, defers), data)


Expand Down

0 comments on commit fe9a45e

Please sign in to comment.