Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#25503 closed Bug (fixed)

Django 1.8 checks crash on ForeignKey to abstract model

Reported by: Andriy Sokolovskiy Owned by: felixxm
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 Changed 4 years ago by Andriy Sokolovskiy

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

comment:2 Changed 4 years ago by Tim Graham

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 Changed 4 years ago by Andriy Sokolovskiy

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 Changed 4 years ago by felixxm

Cc: felisiak.mariusz@… added

comment:5 Changed 4 years ago by felixxm

Owner: changed from nobody to felixxm
Status: newassigned

comment:6 Changed 4 years ago by felixxm

Has patch: set

comment:7 Changed 4 years ago by Tim Graham

Needs tests: set

comment:8 Changed 4 years ago by felixxm

Needs tests: unset

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

Resolution: fixed
Status: assignedclosed

In 914167ab:

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

comment:10 Changed 4 years ago by Tim Graham <timograham@…>

In fbe89307:

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

Backport of 914167abf19d16ac97c0f1f6ae1b08cb377c8f3a from master

comment:11 Changed 4 years ago by Tim Graham <timograham@…>

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