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.
* needs_better_patch: => 0
* type: Uncategorized => Bug
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:1>
* cc: diemersebastien@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:2>
* 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>
* owner: nobody => akki
* status: new => assigned
* version: 1.8 => master
--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:4>
* 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>
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>
* owner: akki =>
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:7>
* status: new => assigned
* owner: (none) => Ingo Klöcker
--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:8>
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>
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>
* status: assigned => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/26605#comment:11>
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>