Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #22708: Typo in autodetector base dependency gen

  • Loading branch information...
commit fe262c0b848c96ef624680d43dc78eae55157967 1 parent 0b57175
@andrewgodwin andrewgodwin authored
View
2  django/db/migrations/autodetector.py
@@ -438,7 +438,7 @@ def generate_created_models(self):
for base in model_state.bases:
if isinstance(base, six.string_types) and "." in base:
base_app_label, base_name = base.split(".", 1)
- dependencies.append((base_app_label, base_name, None, False))
+ dependencies.append((base_app_label, base_name, None, True))
# Generate creation operation
self.add_operation(
app_label,
View
17 tests/migrations/test_autodetector.py
@@ -71,6 +71,7 @@ class AutodetectorTests(TestCase):
custom_user = ModelState("thirdapp", "CustomUser", [("id", models.AutoField(primary_key=True)), ("username", models.CharField(max_length=255))], bases=(AbstractBaseUser, ))
custom_user_no_inherit = ModelState("thirdapp", "CustomUser", [("id", models.AutoField(primary_key=True)), ("username", models.CharField(max_length=255))])
aardvark = ModelState("thirdapp", "Aardvark", [("id", models.AutoField(primary_key=True))])
+ aardvark_based_on_author = ModelState("testapp", "Aardvark", [], bases=("testapp.Author", ))
knight = ModelState("eggs", "Knight", [("id", models.AutoField(primary_key=True))])
rabbit = ModelState("eggs", "Rabbit", [("id", models.AutoField(primary_key=True)), ("knight", models.ForeignKey("eggs.Knight")), ("parent", models.ForeignKey("eggs.Rabbit"))], {"unique_together": [("parent", "knight")]})
@@ -947,3 +948,19 @@ def test_swappable_first_setting(self):
self.assertOperationTypes(changes, 'thirdapp', 0, ["CreateModel", "CreateModel"])
self.assertOperationAttributes(changes, 'thirdapp', 0, 0, name="CustomUser")
self.assertOperationAttributes(changes, 'thirdapp', 0, 1, name="Aardvark")
+
+ @override_settings(AUTH_USER_MODEL="thirdapp.CustomUser")
+ def test_bases_first(self):
+ """
+ Tests that bases of other models come first.
+ """
+ # Make state
+ before = self.make_project_state([])
+ after = self.make_project_state([self.aardvark_based_on_author, self.author_name])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ # Right number of migrations?
+ self.assertNumberMigrations(changes, 'testapp', 1)
+ self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel", "CreateModel"])
+ self.assertOperationAttributes(changes, 'testapp', 0, 0, name="Author")
+ self.assertOperationAttributes(changes, 'testapp', 0, 1, name="Aardvark")
Please sign in to comment.
Something went wrong with that request. Please try again.