diff -r eff0b46ff6fa django/db/models/base.py
a
|
b
|
|
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 | |