summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRigel Di Scala <rigel.discala@propylon.com>2014-10-14 14:10:27 +0100
committerLoic Bistuer <loic.bistuer@gmail.com>2014-10-16 23:49:21 +0700
commita5c77417a651c93036cf963e6da518653115be7e (patch)
treebffcc1d05dae9573b5de308bab0335b733ce1110 /django
parent157f9cf240427bd52aa09a895ac4456da167f876 (diff)
Fixed #23615 -- Validate that a Model instance's "check" attribute is a method.
The "check" name is a reserved word used by Django's check framework, and cannot be redefined as something else other than a method, or the check framework will raise an error. This change amends the django.core.checks.model_check.check_all_models() function, so that it verifies that a model instance's attribute "check" is actually a method. This new check is assigned the id "models.E020".
Diffstat (limited to 'django')
-rw-r--r--django/core/checks/model_checks.py33
1 files changed, 24 insertions, 9 deletions
diff --git a/django/core/checks/model_checks.py b/django/core/checks/model_checks.py
index 3f5a36b41b..3d0d56af58 100644
--- a/django/core/checks/model_checks.py
+++ b/django/core/checks/model_checks.py
@@ -1,28 +1,43 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from itertools import chain
+import inspect
import types
from django.apps import apps
-
-from . import Error, Tags, register
+from django.core.checks import Error, Tags, register
@register(Tags.models)
def check_all_models(app_configs=None, **kwargs):
- errors = [model.check(**kwargs)
- for model in apps.get_models()
- if app_configs is None or model._meta.app_config in app_configs]
- return list(chain(*errors))
+ 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'
+ )
+ )
+ else:
+ errors.extend(model.check(**kwargs))
+ return errors
@register(Tags.models, Tags.signals)
def check_model_signals(app_configs=None, **kwargs):
- """Ensure lazily referenced model signals senders are installed."""
+ """
+ Ensure lazily referenced model signals senders are installed.
+ """
+ # Avoid circular import
from django.db import models
- errors = []
+ errors = []
for name in dir(models.signals):
obj = getattr(models.signals, name)
if isinstance(obj, models.signals.ModelSignal):