Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12121 -- Modified __reduce__ on a model to avoid an infinite r…

…ecursion problem that occurs on Python 2.4. Thanks to emulbreh for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11691 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 08d521efa0de350991a3e72736b0490d747ccc05 1 parent 8dd4a28
Russell Keith-Magee authored November 01, 2009

Showing 1 changed file with 17 additions and 12 deletions. Show diff stats Hide diff stats

  1. 29  django/db/models/base.py
29  django/db/models/base.py
@@ -352,20 +352,25 @@ def __reduce__(self):
352 352
         only module-level classes can be pickled by the default path.
353 353
         """
354 354
         data = self.__dict__
355  
-        if not self._deferred:
356  
-            return super(Model, self).__reduce__()
  355
+        model = self.__class__
  356
+        # The obvious thing to do here is to invoke super().__reduce__()
  357
+        # for the non-deferred case. Don't do that.
  358
+        # On Python 2.4, there is something wierd with __reduce__,
  359
+        # and as a result, the super call will cause an infinite recursion.
  360
+        # See #10547 and #12121.
357 361
         defers = []
358 362
         pk_val = None
359  
-        for field in self._meta.fields:
360  
-            if isinstance(self.__class__.__dict__.get(field.attname),
361  
-                    DeferredAttribute):
362  
-                defers.append(field.attname)
363  
-                if pk_val is None:
364  
-                    # The pk_val and model values are the same for all
365  
-                    # DeferredAttribute classes, so we only need to do this
366  
-                    # once.
367  
-                    obj = self.__class__.__dict__[field.attname]
368  
-                    model = obj.model_ref()
  363
+        if self._deferred:
  364
+            for field in self._meta.fields:
  365
+                if isinstance(self.__class__.__dict__.get(field.attname),
  366
+                        DeferredAttribute):
  367
+                    defers.append(field.attname)
  368
+                    if pk_val is None:
  369
+                        # The pk_val and model values are the same for all
  370
+                        # DeferredAttribute classes, so we only need to do this
  371
+                        # once.
  372
+                        obj = self.__class__.__dict__[field.attname]
  373
+                        model = obj.model_ref()
369 374
 
370 375
         return (model_unpickle, (model, defers), data)
371 376
 

0 notes on commit 08d521e

Please sign in to comment.
Something went wrong with that request. Please try again.