[Django] #26605: Model _default_manager can be None

25 views
Skip to first unread message

Django

unread,
May 11, 2016, 6:14:54 PM5/11/16
to django-...@googlegroups.com
#26605: Model _default_manager can be None
-------------------------------+--------------------
Reporter: sebdiem | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
When using Model inheritance with an abstract model in between, it can
happen that the _default_manager of the actual child class is None. In
this case the //ModelState.from_model// function fails with the following
error:
{{{
django/django/db/migrations/state.py", line 439, in from_model
default_manager_name = force_text(model._default_manager.name)
AttributeError: 'NoneType' object has no attribute 'name'
}}}

The following modified test reproduces the error:
{{{
@override_settings(TEST_SWAPPABLE_MODEL='migrations.SomeFakeModel')
def test_create_swappable(self):
"""
Tests making a ProjectState from an Apps with a swappable model
"""
new_apps = Apps(['migrations'])

class Base(models.Model):
pass

class AbstractAuthor(Base):
class Meta:
abstract = True

class Author(AbstractAuthor):
name = models.CharField(max_length=255)
bio = models.TextField()
age = models.IntegerField(blank=True, null=True)

class Meta(AbstractAuthor.Meta):
app_label = 'migrations'
apps = new_apps
swappable = 'TEST_SWAPPABLE_MODEL'

author_state = ModelState.from_model(Author)
self.assertEqual(author_state.app_label, 'migrations')
self.assertEqual(author_state.name, 'Author')
self.assertEqual([x for x, y in author_state.fields], ['id',
'name', 'bio', 'age'])
self.assertEqual(author_state.fields[1][1].max_length, 255)
self.assertEqual(author_state.fields[2][1].null, False)
self.assertEqual(author_state.fields[3][1].null, True)
self.assertEqual(author_state.options, {'abstract': False,
'swappable': 'TEST_SWAPPABLE_MODEL'})
self.assertEqual(author_state.bases, (models.Model, ))
self.assertEqual(author_state.managers, [])
}}}

Changing the following line in //ModelState.from_model//
{{{
if hasattr(model, "_default_manager"):
}}}
to
{{{
if getattr(model, "_default_manager", None):
}}}
is probably sufficient to fix the bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/26605>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 11, 2016, 6:15:44 PM5/11/16
to django-...@googlegroups.com
#26605: Model _default_manager can be None
----------------------------+--------------------------------------
Reporter: sebdiem | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by sebdiem):

* needs_better_patch: => 0
* type: Uncategorized => Bug
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:1>

Django

unread,
May 11, 2016, 6:16:21 PM5/11/16
to django-...@googlegroups.com
#26605: Model _default_manager can be None
----------------------------+--------------------------------------
Reporter: sebdiem | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by sebdiem):

* cc: diemersebastien@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:2>

Django

unread,
May 12, 2016, 11:51:27 AM5/12/16
to django-...@googlegroups.com
#26605: Abstract model inheriting concrete model crashes migrations
----------------------------+------------------------------------
Reporter: sebdiem | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted
* needs_tests: 0 => 1


Comment:

There's an abstract model inheriting a concrete one in
`tests/model_inheritance_regress/models.py` so this seems to be a
supported use case. A regression test might go in
`tests/migrations/test_state.py`.

--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:3>

Django

unread,
May 21, 2016, 8:23:07 AM5/21/16
to django-...@googlegroups.com
#26605: Abstract model inheriting concrete model crashes migrations
----------------------------+------------------------------------
Reporter: sebdiem | Owner: akki
Type: Bug | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by akki):

* owner: nobody => akki
* status: new => assigned
* version: 1.8 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:4>

Django

unread,
Jun 28, 2016, 7:33:00 PM6/28/16
to django-...@googlegroups.com
#26605: Abstract model inheriting concrete model crashes migrations
----------------------------+------------------------------------
Reporter: sebdiem | Owner: akki
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by charettes):

* version: master => 1.8


Comment:

As noted on the PR this bug that has been fixed on the master branch (and
1.10.x) by the manager state refactor.

Based on our policy I don't think this warrant a backport to 1.9.x and
1.8.x but adding the test to the suite wouldn't hurt.

--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:5>

Django

unread,
Jun 29, 2016, 1:09:13 AM6/29/16
to django-...@googlegroups.com
#26605: Abstract model inheriting concrete model crashes migrations
----------------------------+------------------------------------
Reporter: sebdiem | Owner: akki
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Description changed by sebdiem:

Old description:

New description:

class Base(models.Model):
pass

See also PR https://github.com/django/django/pull/6847

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:6>

Django

unread,
Jun 30, 2016, 12:22:53 AM6/30/16
to django-...@googlegroups.com
#26605: Abstract model inheriting concrete model crashes migrations
----------------------------+------------------------------------
Reporter: sebdiem | Owner:
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by akki):

* owner: akki =>
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:7>

Django

unread,
Apr 7, 2017, 6:42:22 AM4/7/17
to django-...@googlegroups.com
#26605: Abstract model inheriting concrete model crashes migrations
----------------------------------+----------------------------------------
Reporter: Sébastien Diemer | Owner: Ingo Klöcker
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Ingo Klöcker):

* status: new => assigned

* owner: (none) => Ingo Klöcker


--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:8>

Django

unread,
Apr 7, 2017, 6:58:44 AM4/7/17
to django-...@googlegroups.com
#26605: Abstract model inheriting concrete model crashes migrations
----------------------------------+----------------------------------------
Reporter: Sébastien Diemer | Owner: Ingo Klöcker
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------

Comment (by Ingo Klöcker):

Added [https://github.com/django/django/pull/8325 PR] with the test from
the original PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:9>

Django

unread,
Apr 7, 2017, 4:34:15 PM4/7/17
to django-...@googlegroups.com
#26605: Abstract model inheriting concrete model crashes migrations
----------------------------------+----------------------------------------
Reporter: Sébastien Diemer | Owner: Ingo Klöcker
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"67b2b1f116aceee12922d2a8ff832382bca7e8ad" 67b2b1f1]:
{{{
#!CommitTicketReference repository=""
revision="67b2b1f116aceee12922d2a8ff832382bca7e8ad"
Refs #26605 -- Added migrations state test for a swappable model
inheriting an abstract model inheriting concrete model.

Thanks Sébastien Diemer for the report and test.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:10>

Django

unread,
Apr 7, 2017, 6:06:09 PM4/7/17
to django-...@googlegroups.com
#26605: Abstract model inheriting concrete model crashes migrations
----------------------------------+----------------------------------------
Reporter: Sébastien Diemer | Owner: Ingo Klöcker
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Tim Graham):

* status: assigned => closed
* resolution: => fixed


--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:11>

Django

unread,
Apr 10, 2017, 8:13:55 AM4/10/17
to django-...@googlegroups.com
#26605: Abstract model inheriting concrete model crashes migrations
----------------------------------+----------------------------------------
Reporter: Sébastien Diemer | Owner: Ingo Klöcker
Type: Bug | Status: closed
Component: Migrations | Version: 1.8

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"eb9a3bd63a2eac2805ce8a23640ba4d7bc31699c" eb9a3bd]:
{{{
#!CommitTicketReference repository=""
revision="eb9a3bd63a2eac2805ce8a23640ba4d7bc31699c"
Refs #26605 -- Isolated a migrations state test.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:12>

Reply all
Reply to author
Forward
0 new messages