[Django] #33234: Migrations autodetector breaking with proxy models inheriting from mixin

46 views
Skip to first unread message

Django

unread,
Oct 28, 2021, 12:02:34 PM10/28/21
to django-...@googlegroups.com
#33234: Migrations autodetector breaking with proxy models inheriting from mixin
---------------------------------------+-----------------------------
Reporter: Kevin Marsh | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.0
Severity: Normal | Keywords: proxy model
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------+-----------------------------
So I've run into an issue with the new automigrations feature in Django
4.0b1 (and 4.0a1) relating to proxy models inheriting from a non-Model
class.

For examples given these three models:
{{{#!python
from django.db import models

class MyMixin:
...

class MyRealModel(MyMixin, models.Model):
...

class MyBaseModel(models.Model):
...

class MyProxyModel(MyMixin, MyBaseModel):
class Meta:
proxy = True
}}}

Running `migrate`/`makemigrations` will result in `MyProxyModel` crashing
when it tries running `_find_concrete_model_from_proxy`:
{{{
File
"/some/annonymized/path/django/core/management/commands/makemigrations.py",
line 172, in handle
changes = autodetector.changes(
File "/some/annonymized/path/django/db/migrations/autodetector.py", line
43, in changes
changes = self._detect_changes(convert_apps, graph)
File "/some/annonymized/path/django/db/migrations/autodetector.py", line
156, in _detect_changes
self.to_state.resolve_fields_and_relations()
File "/some/annonymized/path/django/db/migrations/state.py", line 449,
in resolve_fields_and_relations
concretes, proxies =
self._get_concrete_models_mapping_and_proxy_models()
File "/some/annonymized/path/django/db/migrations/state.py", line 470,
in _get_concrete_models_mapping_and_proxy_models
concrete_models_mapping[model_key] =
self._find_concrete_model_from_proxy(
File "/some/annonymized/path/django/db/migrations/state.py", line 479,
in _find_concrete_model_from_proxy
base_key = make_model_tuple(base)
File "/some/annonymized/path/django/db/models/utils.py", line 18, in
make_model_tuple
model_tuple = model._meta.app_label, model._meta.model_name
AttributeError: type object 'MyMixin' has no attribute '_meta'
}}}


Changing `MyMixin` to inherit from `models.Model` prevents this crash but
might not always be possible depending on how the user is using that
mixin. Or if we've decided that all inheritance for proxy models must be
from `models.Model` then that should be flagged up more explicitly to
developers (eg. checking for it in `ModelBase.__new__` or something).

--
Ticket URL: <https://code.djangoproject.com/ticket/33234>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 28, 2021, 12:46:18 PM10/28/21
to django-...@googlegroups.com
#33234: Migrations autodetector breaking with proxy models inheriting from mixin
---------------------------------+------------------------------------

Reporter: Kevin Marsh | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: proxy model | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* cc: David Wobrock (added)
* stage: Unreviewed => Accepted
* severity: Normal => Release blocker


Old description:

New description:

So I've run into an issue with the new automigrations feature in Django
4.0b1 (and 4.0a1) relating to proxy models inheriting from a non-Model
class.

For examples given these three models:
{{{#!python
from django.db import models

class MyMixin:
...

class MyBaseModel(models.Model):
...

--

Comment:

Thanks for the report!

Regression in aa4acc164d1247c0de515c959f7b09648b57dc42.
Reproduced at afeafd6036616bac8263d762c1610f22241c0187.

--
Ticket URL: <https://code.djangoproject.com/ticket/33234#comment:1>

Django

unread,
Oct 29, 2021, 3:33:57 AM10/29/21
to django-...@googlegroups.com
#33234: Migrations autodetector breaking with proxy models inheriting from mixin
-------------------------------------+-------------------------------------
Reporter: Kevin Marsh | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: proxy model | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Mariusz Felisiak
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33234#comment:2>

Django

unread,
Oct 29, 2021, 3:43:38 AM10/29/21
to django-...@googlegroups.com
#33234: Migrations autodetector breaking with proxy models inheriting from mixin
-------------------------------------+-------------------------------------
Reporter: Kevin Marsh | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: proxy model | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/15034 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33234#comment:3>

Django

unread,
Nov 2, 2021, 9:36:39 AM11/2/21
to django-...@googlegroups.com
#33234: Migrations autodetector breaking with proxy models inheriting from mixin
-------------------------------------+-------------------------------------
Reporter: Kevin Marsh | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: proxy model | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33234#comment:4>

Django

unread,
Nov 2, 2021, 3:11:00 PM11/2/21
to django-...@googlegroups.com
#33234: Migrations autodetector breaking with proxy models inheriting from mixin
-------------------------------------+-------------------------------------
Reporter: Kevin Marsh | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution: fixed

Keywords: proxy model | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* resolution: => fixed


Comment:

Fixed in
[https://github.com/django/django/commit/dab48b7482295956973879d15bfd4d3bb0718772
dab48b7482295956973879d15bfd4d3bb0718772] and
[https://github.com/django/django/commit/e2fe0429abb1fafee7643b9361b808f982ddaf98
e2fe0429abb1fafee7643b9361b808f982ddaf98].

--
Ticket URL: <https://code.djangoproject.com/ticket/33234#comment:5>

Reply all
Reply to author
Forward
0 new messages