summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-04-08 10:43:38 +0200
committerGitHub <noreply@github.com>2020-04-08 10:43:38 +0200
commitdb6933a032c850153a688b6c977691b37ca02745 (patch)
treee5567582fe4cf74e3b9050d67e4a048d58a20ddd /tests
parent2e67e80fbe0accd5f256415ac28af8bd82eeaced (diff)
downloaddjango-db6933a032c850153a688b6c977691b37ca02745.tar.gz
Refs #30966 -- Added test for reloading related model state on non-relational changes.
Thanks Markus Holtermann for initial test. Fixed in 1d16c5d562a67625f7309cc7765b8c57d49bf182.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_state.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py
index 44d4cdf268..1bb6b66c3c 100644
--- a/tests/migrations/test_state.py
+++ b/tests/migrations/test_state.py
@@ -532,6 +532,37 @@ class StateTests(SimpleTestCase):
project_state.add_model(ModelState.from_model(B))
self.assertEqual(len(project_state.apps.get_models()), 2)
+ def test_reload_related_model_on_non_relational_fields(self):
+ """
+ The model is reloaded even on changes that are not involved in
+ relations. Other models pointing to or from it are also reloaded.
+ """
+ project_state = ProjectState()
+ project_state.apps # Render project state.
+ project_state.add_model(ModelState('migrations', 'A', []))
+ project_state.add_model(ModelState('migrations', 'B', [
+ ('a', models.ForeignKey('A', models.CASCADE)),
+ ]))
+ project_state.add_model(ModelState('migrations', 'C', [
+ ('b', models.ForeignKey('B', models.CASCADE)),
+ ('name', models.TextField()),
+ ]))
+ project_state.add_model(ModelState('migrations', 'D', [
+ ('a', models.ForeignKey('A', models.CASCADE)),
+ ]))
+ operation = AlterField(
+ model_name='C',
+ name='name',
+ field=models.TextField(blank=True),
+ )
+ operation.state_forwards('migrations', project_state)
+ project_state.reload_model('migrations', 'a', delay=True)
+ A = project_state.apps.get_model('migrations.A')
+ B = project_state.apps.get_model('migrations.B')
+ D = project_state.apps.get_model('migrations.D')
+ self.assertIs(B._meta.get_field('a').related_model, A)
+ self.assertIs(D._meta.get_field('a').related_model, A)
+
def test_reload_model_relationship_consistency(self):
project_state = ProjectState()
project_state.add_model(ModelState('migrations', 'A', []))