summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-11-02 15:34:08 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-11-02 15:35:52 +0100
commite2fe0429abb1fafee7643b9361b808f982ddaf98 (patch)
tree9c24adfa118dfda7c229ff1b11e60989e2a6b742
parentb4ad6e32cad0ec69dbccf3541289b28c8d6b7288 (diff)
[4.0.x] Fixed #33234 -- Fixed autodetector crash for proxy models inheriting from non-model class.
Regression in aa4acc164d1247c0de515c959f7b09648b57dc42. Thanks Kevin Marsh for the report. Backport of dab48b7482295956973879d15bfd4d3bb0718772 from main
-rw-r--r--django/db/migrations/state.py2
-rw-r--r--tests/migrations/test_autodetector.py23
2 files changed, 25 insertions, 0 deletions
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py
index 2927e66f83..d3e2098a67 100644
--- a/django/db/migrations/state.py
+++ b/django/db/migrations/state.py
@@ -476,6 +476,8 @@ class ProjectState:
def _find_concrete_model_from_proxy(self, proxy_models, model_state):
for base in model_state.bases:
+ if not (isinstance(base, str) or issubclass(base, models.Model)):
+ continue
base_key = make_model_tuple(base)
base_state = proxy_models.get(base_key)
if not base_state:
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 67cc39dec7..fb42a8a455 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -1779,6 +1779,29 @@ class AutodetectorTests(TestCase):
self.assertOperationAttributes(changes, "testapp", 0, 0, name="AuthorProxy")
self.assertOperationAttributes(changes, "testapp", 0, 1, name="AuthorProxy", options={})
+ def test_proxy_non_model_parent(self):
+ class Mixin:
+ pass
+
+ author_proxy_non_model_parent = ModelState(
+ 'testapp',
+ 'AuthorProxy',
+ [],
+ {'proxy': True},
+ (Mixin, 'testapp.author'),
+ )
+ changes = self.get_changes(
+ [self.author_empty],
+ [self.author_empty, author_proxy_non_model_parent],
+ )
+ self.assertNumberMigrations(changes, 'testapp', 1)
+ self.assertOperationTypes(changes, 'testapp', 0, ['CreateModel'])
+ self.assertOperationAttributes(
+ changes, 'testapp', 0, 0, name='AuthorProxy',
+ options={'proxy': True, 'indexes': [], 'constraints': []},
+ bases=(Mixin, 'testapp.author'),
+ )
+
def test_proxy_custom_pk(self):
"""
#23415 - The autodetector must correctly deal with custom FK on proxy