#24291: Migrations fail with unused swappable model
----------------------------+--------------------------------------
Reporter: knbk | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by knbk):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Test that currently fails:
{{{
diff --git a/tests/migrations/test_state.py
b/tests/migrations/test_state.py
index a7dbdbe..ca7a21e 100644
--- a/tests/migrations/test_state.py
+++ b/tests/migrations/test_state.py
@@ -2,7 +2,7 @@
from django.db import models
from django.db.migrations.operations import RemoveField
from django.db.migrations.state import ProjectState, ModelState,
InvalidBasesError
-from django.test import TestCase
+from django.test import TestCase, override_settings
from .models import (FoodManager, FoodQuerySet, ModelWithCustomBase,
NoMigrationFoodManager)
@@ -543,6 +543,37 @@ def test_manager_refer_correct_model_version(self):
self.assertIsNot(old_model.food_mgr.model,
new_model.food_mgr.model)
self.assertIsNot(old_model.food_qs.model,
new_model.food_qs.model)
+ @override_settings(TEST_SWAPPABLE_MODEL="migrations.SomeFakeModel")
+ def test_create_swappable(self):
+ """
+ Tests making a ProjectState from an Apps
+ """
+
+ new_apps = Apps(["migrations"])
+
+ class Author(models.Model):
+ name = models.CharField(max_length=255)
+ bio = models.TextField()
+ age = models.IntegerField(blank=True, null=True)
+
+ class Meta:
+ app_label = "migrations"
+ apps = new_apps
+ swappable = "TEST_SWAPPABLE_MODEL"
+
+
+ project_state = ProjectState.from_apps(new_apps)
+ author_state = project_state.models['migrations', '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, {"swappable":
"TEST_SWAPPABLE_MODEL"})
+ self.assertEqual(author_state.bases, (models.Model, ))
+
class ModelStateTests(TestCase):
def test_custom_model_base(self):
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24291#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/062.d3720451e986c6279e8aeebeae7fc541%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.