Fixed #22951 -- Checked for types during deep_deconstruct migration serialization process.
Thanks Sam Hartsfield for the report.
This commit is contained in:
parent
f36ab2d3f2
commit
4680d25df2
|
@ -49,7 +49,7 @@ class MigrationAutodetector(object):
|
||||||
Used for full comparison for rename/alter; sometimes a single-level
|
Used for full comparison for rename/alter; sometimes a single-level
|
||||||
deconstruction will not compare correctly.
|
deconstruction will not compare correctly.
|
||||||
"""
|
"""
|
||||||
if not hasattr(obj, 'deconstruct'):
|
if not hasattr(obj, 'deconstruct') or isinstance(obj, type):
|
||||||
return obj
|
return obj
|
||||||
deconstructed = obj.deconstruct()
|
deconstructed = obj.deconstruct()
|
||||||
if isinstance(obj, models.Field):
|
if isinstance(obj, models.Field):
|
||||||
|
|
|
@ -16,3 +16,5 @@ Bugfixes
|
||||||
|
|
||||||
* Reinstated missing ``CHECK`` SQL clauses which were omitted on some backends
|
* Reinstated missing ``CHECK`` SQL clauses which were omitted on some backends
|
||||||
when not using migrations (:ticket:`23416`).
|
when not using migrations (:ticket:`23416`).
|
||||||
|
|
||||||
|
* Fixed serialization of ``type`` objects in migrations (:ticket:`22951`).
|
||||||
|
|
|
@ -702,6 +702,31 @@ class AutodetectorTests(TestCase):
|
||||||
changes = autodetector._detect_changes()
|
changes = autodetector._detect_changes()
|
||||||
self.assertEqual(changes, {})
|
self.assertEqual(changes, {})
|
||||||
|
|
||||||
|
def test_deconstruct_type(self):
|
||||||
|
"""
|
||||||
|
#22951 -- Uninstanted classes with deconstruct are correctly returned
|
||||||
|
by deep_deconstruct during serialization.
|
||||||
|
"""
|
||||||
|
author = ModelState(
|
||||||
|
"testapp",
|
||||||
|
"Author",
|
||||||
|
[
|
||||||
|
("id", models.AutoField(primary_key=True)),
|
||||||
|
("name", models.CharField(
|
||||||
|
max_length=200,
|
||||||
|
# IntegerField intentionally not instantiated.
|
||||||
|
default=models.IntegerField,
|
||||||
|
))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
# Make state
|
||||||
|
before = self.make_project_state([])
|
||||||
|
after = self.make_project_state([author])
|
||||||
|
autodetector = MigrationAutodetector(before, after)
|
||||||
|
changes = autodetector._detect_changes()
|
||||||
|
self.assertNumberMigrations(changes, 'testapp', 1)
|
||||||
|
self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel"])
|
||||||
|
|
||||||
def test_replace_string_with_foreignkey(self):
|
def test_replace_string_with_foreignkey(self):
|
||||||
"""
|
"""
|
||||||
Adding an FK in the same "spot" as a deleted CharField should work. (#22300).
|
Adding an FK in the same "spot" as a deleted CharField should work. (#22300).
|
||||||
|
|
Loading…
Reference in New Issue