summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2015-11-17 00:39:28 -0500
committerSimon Charette <charette.s@gmail.com>2016-01-06 20:00:07 -0500
commita08fda2111d811aa53f11218fa03f3300dfff4cb (patch)
tree0263cf99adf17c5123b3a53c686f637d5b40eda4 /django
parent3096f4b0829a005c67a14cc4bb6d345aa32672a1 (diff)
Fixed #25746 -- Isolated inlined test models registration.
Thanks to Tim for the review.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/auth/checks.py18
-rw-r--r--django/contrib/contenttypes/checks.py12
-rw-r--r--django/core/checks/model_checks.py32
3 files changed, 42 insertions, 20 deletions
diff --git a/django/contrib/auth/checks.py b/django/contrib/auth/checks.py
index 2d47377c9a..75f9542346 100644
--- a/django/contrib/auth/checks.py
+++ b/django/contrib/auth/checks.py
@@ -6,10 +6,22 @@ from django.conf import settings
from django.core import checks
-def check_user_model(**kwargs):
- errors = []
+def check_user_model(app_configs=None, **kwargs):
+ if app_configs is None:
+ cls = apps.get_model(settings.AUTH_USER_MODEL)
+ else:
+ app_label, model_name = settings.AUTH_USER_MODEL.split('.')
+ for app_config in app_configs:
+ if app_config.label == app_label:
+ cls = app_config.get_model(model_name)
+ break
+ else:
+ # Checks might be run against a set of app configs that don't
+ # include the specified user model. In this case we simply don't
+ # perform the checks defined below.
+ return []
- cls = apps.get_model(settings.AUTH_USER_MODEL)
+ errors = []
# Check that REQUIRED_FIELDS is a list
if not isinstance(cls.REQUIRED_FIELDS, (list, tuple)):
diff --git a/django/contrib/contenttypes/checks.py b/django/contrib/contenttypes/checks.py
index 1b3df21353..3db58cfdbe 100644
--- a/django/contrib/contenttypes/checks.py
+++ b/django/contrib/contenttypes/checks.py
@@ -1,17 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+from itertools import chain
+
from django.apps import apps
from django.utils import six
-def check_generic_foreign_keys(**kwargs):
+def check_generic_foreign_keys(app_configs=None, **kwargs):
from .fields import GenericForeignKey
+ if app_configs is None:
+ models = apps.get_models()
+ else:
+ models = chain.from_iterable(app_config.get_models() for app_config in app_configs)
errors = []
fields = (obj
- for cls in apps.get_models()
- for obj in six.itervalues(vars(cls))
+ for model in models
+ for obj in six.itervalues(vars(model))
if isinstance(obj, GenericForeignKey))
for field in fields:
errors.extend(field.check())
diff --git a/django/core/checks/model_checks.py b/django/core/checks/model_checks.py
index 3d0d56af58..b312602c6c 100644
--- a/django/core/checks/model_checks.py
+++ b/django/core/checks/model_checks.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
import inspect
import types
+from itertools import chain
from django.apps import apps
from django.core.checks import Error, Tags, register
@@ -11,21 +12,24 @@ from django.core.checks import Error, Tags, register
@register(Tags.models)
def check_all_models(app_configs=None, **kwargs):
errors = []
- for model in apps.get_models():
- if app_configs is None or model._meta.app_config in app_configs:
- if not inspect.ismethod(model.check):
- errors.append(
- Error(
- "The '%s.check()' class method is "
- "currently overridden by %r." % (
- model.__name__, model.check),
- hint=None,
- obj=model,
- id='models.E020'
- )
+ if app_configs is None:
+ models = apps.get_models()
+ else:
+ models = chain.from_iterable(app_config.get_models() for app_config in app_configs)
+ for model in models:
+ if not inspect.ismethod(model.check):
+ errors.append(
+ Error(
+ "The '%s.check()' class method is "
+ "currently overridden by %r." % (
+ model.__name__, model.check),
+ hint=None,
+ obj=model,
+ id='models.E020'
)
- else:
- errors.extend(model.check(**kwargs))
+ )
+ else:
+ errors.extend(model.check(**kwargs))
return errors