diff options
| author | Fabian Büchler <fabian@buechler.io> | 2022-01-19 16:27:07 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-21 06:44:53 +0100 |
| commit | eeff1787b0aa23016e4844c0f537d5093a95a356 (patch) | |
| tree | fdd07ee9593a6368f450215299bc85ce6ad33af0 /tests | |
| parent | f605e85af9763a3940369bb79462f2cb466288f6 (diff) | |
Fixed #33449 -- Fixed makemigrations crash on models without Meta.order_with_respect_to but with _order field.
Regression in aa4acc164d1247c0de515c959f7b09648b57dc42.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_state.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py index 8ad0d19500..9536f19e83 100644 --- a/tests/migrations/test_state.py +++ b/tests/migrations/test_state.py @@ -959,6 +959,44 @@ class StateTests(SimpleTestCase): ["id", "author"], ) + def test_modelstate_get_field_order_wrt(self): + new_apps = Apps() + + class Author(models.Model): + name = models.TextField() + + class Meta: + app_label = 'migrations' + apps = new_apps + + class Book(models.Model): + author = models.ForeignKey(Author, models.CASCADE) + + class Meta: + app_label = 'migrations' + apps = new_apps + order_with_respect_to = 'author' + + model_state = ModelState.from_model(Book) + order_wrt_field = model_state.get_field('_order') + self.assertIsInstance(order_wrt_field, models.ForeignKey) + self.assertEqual(order_wrt_field.related_model, 'migrations.author') + + def test_modelstate_get_field_no_order_wrt_order_field(self): + new_apps = Apps() + + class HistoricalRecord(models.Model): + _order = models.PositiveSmallIntegerField() + + class Meta: + app_label = 'migrations' + apps = new_apps + + model_state = ModelState.from_model(HistoricalRecord) + order_field = model_state.get_field('_order') + self.assertIsNone(order_field.related_model) + self.assertIsInstance(order_field, models.PositiveSmallIntegerField) + def test_manager_refer_correct_model_version(self): """ #24147 - Managers refer to the correct version of a |
