Ticket #18590: 18590-1.diff

File 18590-1.diff, 2.9 KB (added by Claude Paroz, 12 years ago)

Removed Python 2.4 workaround

  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index 82283d5..79af1cb 100644
    a b from django.db.models.fields.related import (ManyToOneRel,  
    1616from django.db import (router, transaction, DatabaseError,
    1717    DEFAULT_DB_ALIAS)
    1818from django.db.models.query import Q
    19 from django.db.models.query_utils import DeferredAttribute
     19from django.db.models.query_utils import DeferredAttribute, deferred_class_factory
    2020from django.db.models.deletion import Collector
    2121from django.db.models.options import Options
    2222from django.db.models import signals
    class Model(object):  
    400400        need to do things manually, as they're dynamically created classes and
    401401        only module-level classes can be pickled by the default path.
    402402        """
     403        if not self._deferred:
     404            return super(Model, self).__reduce__()
    403405        data = self.__dict__
    404         model = self.__class__
    405         # The obvious thing to do here is to invoke super().__reduce__()
    406         # for the non-deferred case. Don't do that.
    407         # On Python 2.4, there is something weird with __reduce__,
    408         # and as a result, the super call will cause an infinite recursion.
    409         # See #10547 and #12121.
    410406        defers = []
    411         if self._deferred:
    412             from django.db.models.query_utils import deferred_class_factory
    413             factory = deferred_class_factory
    414             for field in self._meta.fields:
    415                 if isinstance(self.__class__.__dict__.get(field.attname),
    416                         DeferredAttribute):
    417                     defers.append(field.attname)
    418             model = self._meta.proxy_for_model
    419         else:
    420             factory = simple_class_factory
    421         return (model_unpickle, (model, defers, factory), data)
     407        for field in self._meta.fields:
     408            if isinstance(self.__class__.__dict__.get(field.attname),
     409                    DeferredAttribute):
     410                defers.append(field.attname)
     411        model = self._meta.proxy_for_model
     412        return (model_unpickle, (model, defers), data)
    422413
    423414    def _get_pk_val(self, meta=None):
    424415        if not meta:
    def get_absolute_url(opts, func, self, *args, **kwargs):  
    926917class Empty(object):
    927918    pass
    928919
    929 def simple_class_factory(model, attrs):
    930     """Used to unpickle Models without deferred fields.
    931 
    932     We need to do this the hard way, rather than just using
    933     the default __reduce__ implementation, because of a
    934     __deepcopy__ problem in Python 2.4
    935     """
    936     return model
    937 
    938 def model_unpickle(model, attrs, factory):
     920def model_unpickle(model, attrs):
    939921    """
    940922    Used to unpickle Model subclasses with deferred fields.
    941923    """
    942     cls = factory(model, attrs)
     924    cls = deferred_class_factory(model, attrs)
    943925    return cls.__new__(cls)
    944926model_unpickle.__safe_for_unpickle__ = True
    945927
Back to Top