Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25503 closed Bug (fixed)

Django 1.8 checks crash on ForeignKey to abstract model

Reported by: Andriy Sokolovskiy Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: 1.8
Severity: Release blocker Keywords:
Cc: me@…, felisiak.mariusz@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Consider some models:

from django.db import models


class ModelA(models.Model):
    test = models.CharField(blank=True, max_length=123)

    class Meta:
        abstract = True


class SomeOtherModel(models.Model):
    test_fk = models.ForeignKey(ModelA)

On django 1.8.5 it fails like:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/projpath/.env/lib/python2.7/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
    utility.execute()
  File "/projpath/.env/lib/python2.7/site-packages/django/core/management/__init__.py", line 343, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/projpath/.env/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/projpath/.env/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
    self.check()
  File "/projpath/.env/lib/python2.7/site-packages/django/core/management/base.py", line 482, in check
    include_deployment_checks=include_deployment_checks,
  File "/projpath/.env/lib/python2.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/projpath/.env/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 28, in check_all_models
    errors.extend(model.check(**kwargs))
  File "/projpath/.env/lib/python2.7/site-packages/django/db/models/base.py", line 1205, in check
    errors.extend(cls._check_fields(**kwargs))
  File "/projpath/.env/lib/python2.7/site-packages/django/db/models/base.py", line 1282, in _check_fields
    errors.extend(field.check(**kwargs))
  File "/projpath/.env/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1834, in check
    errors = super(ForeignKey, self).check(**kwargs)
  File "/projpath/.env/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1507, in check
    errors.extend(self._check_unique_target())
  File "/projpath/.env/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1527, in _check_unique_target
    for rel_field in self.foreign_related_fields)
  File "/projpath/.env/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1527, in <genexpr>
    for rel_field in self.foreign_related_fields)
AttributeError: 'NoneType' object has no attribute 'unique'

On django 1.7 it throws error:

CommandError: System check identified some issues:

ERRORS:
blankapp.SomeOtherModel.test_fk: (fields.E300) Field defines a relation with model 'ModelA', which is either not installed, or is abstract.

Change History (11)

comment:1 by Andriy Sokolovskiy, 9 years ago

It is detecting fields.E300 correctly, but failing on ForeignObject.self._check_unique_target()

comment:2 by Tim Graham, 9 years ago

Severity: NormalRelease blocker
Summary: Django 1.8 is not detecting ForeignKey to abstract model correctlyDjango 1.8 checks crash on ForeignKey to abstract model
Triage Stage: UnreviewedAccepted

comment:3 by Andriy Sokolovskiy, 9 years ago

On 1.7 there are no bug because while checking unique target it is returning here https://github.com/django/django/blob/e03fe2f6bbad7305146d0e19e5e9a36eda2b982c/django/db/models/fields/related.py#L1344

On 1.8 and on master it is not returning in that place which is producing an error.

comment:4 by Mariusz Felisiak, 9 years ago

Cc: felisiak.mariusz@… added

comment:5 by Mariusz Felisiak, 9 years ago

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:6 by Mariusz Felisiak, 9 years ago

Has patch: set

comment:7 by Tim Graham, 9 years ago

Needs tests: set

comment:8 by Mariusz Felisiak, 9 years ago

Needs tests: unset

comment:9 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 914167ab:

Fixed #25503 -- Fixed system check crash on ForeignKey to abstract model.

comment:10 by Tim Graham <timograham@…>, 9 years ago

In fbe89307:

[1.9.x] Fixed #25503 -- Fixed system check crash on ForeignKey to abstract model.

Backport of 914167abf19d16ac97c0f1f6ae1b08cb377c8f3a from master

comment:11 by Tim Graham <timograham@…>, 9 years ago

In 4ec96b7:

[1.8.x] Fixed #25503 -- Fixed system check crash on ForeignKey to abstract model.

Backport of 914167abf19d16ac97c0f1f6ae1b08cb377c8f3a from master

Note: See TracTickets for help on using tickets.
Back to Top