From 0a65da941c1643f0ce8d2c9644b12d3f07319c6d Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 5 Apr 2014 20:58:59 +0200 Subject: [PATCH] Fixed #22236 -- Removed inappropriate usage of signals Thanks Aymeric Augustin for the report and Tim Graham for the review. --- django/db/models/base.py | 11 ++++++----- django/db/models/manager.py | 6 +----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index e0bb1690ec..589d793627 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -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) diff --git a/django/db/models/manager.py b/django/db/models/manager.py index 4ab917418e..6d77ef59df 100644 --- a/django/db/models/manager.py +++ b/django/db/models/manager.py @@ -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):