#23615 closed Bug (fixed)
Naming a model Check causes Django's check framework to fail with an exception
Reported by: | Bram Duvigneau | Owned by: | Rigel Di Scala |
---|---|---|---|
Component: | Core (System checks) | Version: | 1.7 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This causes an SingleRelatedObjectDescriptor is not callable error.
Change History (11)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
I've managed to reproduce with these models:
class Foo(models.Model): pass class Bar(models.Model): check = models.ForeignKey('Foo')
It turns out that the name of the model is not the issue but the name of the field is.
Note however that using check = models.IntegerField()
doesn't trigger the error.
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 10 years ago
I can replicate the issue.
The exception is raised, when running my test using the Django test management command, here: https://github.com/django/django/blob/master/django/core/management/base.py#L418
if (self.requires_system_checks and not options.get('skip_validation') and # Remove at the end of deprecation for `skip_validation`. not options.get('skip_checks')): self.check()
bmispelon
and I found that the problem actually originates here:
https://github.com/django/django/blob/master/django/core/checks/model_checks.py#L14
@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))
We would therefore need to check (no pun intended) that the check
attribute on the model
instance does not resolve to a field, before actually calling it as a method, something to the tune of:
if mdl._meta.get_field_by_name("check"): pass
comment:5 by , 10 years ago
Has patch: | set |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
I have submitted a pull request that amends the behavior of check_all_models(), so that is checks for this problem and returns a meaningful error message.
comment:6 by , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → new |
@zedr thanks for the patch. In term of procedure though we only mark a ticket as fixed once a patch has been merged. As a matter of fact, tickets close themselves automatically provided the commit messages have the right format.
comment:8 by , 10 years ago
Summary: | Naming a model Check causes Django's check framework to fail with an acception → Naming a model Check causes Django's check framework to fail with an exception |
---|
comment:9 by , 10 years ago
Severity: | Normal → Release blocker |
---|
It seems like we should figure this out before the next release.
comment:10 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I can't reproduce this. Is the Check model related to another model? Could you post a traceback?