Fixed #22236 -- Removed inappropriate usage of signals

Thanks Aymeric Augustin for the report and Tim Graham for the review.
This commit is contained in:
Claude Paroz 2014-04-05 20:58:59 +02:00
parent fd23c06023
commit 0a65da941c
2 changed files with 7 additions and 10 deletions

View File

@ -7,20 +7,20 @@ import warnings
from django.apps import apps
from django.apps.config import MODELS_MODULE_NAME
import django.db.models.manager # NOQA: Imported to register signal handler.
from django.conf import settings
from django.core import checks
from django.core.exceptions import (ObjectDoesNotExist,
MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS)
from django.db import (router, transaction, DatabaseError,
DEFAULT_DB_ALIAS)
from django.db.models.deletion import Collector
from django.db.models.fields import AutoField, FieldDoesNotExist
from django.db.models.fields.related import (ForeignObjectRel, ManyToOneRel,
OneToOneField, add_lazy_relation)
from django.db import (router, transaction, DatabaseError,
DEFAULT_DB_ALIAS)
from django.db.models.manager import ensure_default_manager
from django.db.models.options import Options
from django.db.models.query import Q
from django.db.models.query_utils import DeferredAttribute, deferred_class_factory
from django.db.models.deletion import Collector
from django.db.models.options import Options
from django.db.models import signals
from django.utils import six
from django.utils.deprecation import RemovedInDjango19Warning
@ -353,6 +353,7 @@ class ModelBase(type):
cls.get_absolute_url = update_wrapper(curry(get_absolute_url, opts, cls.get_absolute_url),
cls.get_absolute_url)
ensure_default_manager(cls)
signals.class_prepared.send(sender=cls)

View File

@ -3,20 +3,18 @@ import inspect
from django.db import router
from django.db.models.query import QuerySet
from django.db.models import signals
from django.db.models.fields import FieldDoesNotExist
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
def ensure_default_manager(sender, **kwargs):
def ensure_default_manager(cls):
"""
Ensures that a Model subclass contains a default manager and sets the
_default_manager attribute on the class. Also sets up the _base_manager
points to a plain Manager instance (which could be the same as
_default_manager if it's not a subclass of Manager).
"""
cls = sender
if cls._meta.abstract:
setattr(cls, 'objects', AbstractManagerDescriptor(cls))
return
@ -48,8 +46,6 @@ def ensure_default_manager(sender, **kwargs):
return
raise AssertionError("Should never get here. Please report a bug, including your model and model manager setup.")
signals.class_prepared.connect(ensure_default_manager)
@python_2_unicode_compatible
class BaseManager(object):