[Django] #34719: modelBase.add_to_class is ineffective when called in __init_subclass__ of an abstract Model

20 views
Skip to first unread message

Django

unread,
Jul 17, 2023, 4:42:13 PM7/17/23
to django-...@googlegroups.com
#34719: modelBase.add_to_class is ineffective when called in __init_subclass__ of
an abstract Model
-------------------------------------+-------------------------------------
Reporter: piscvau | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 4.1
layer (models, ORM) | Keywords: dynamic model
Severity: Normal | modification
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Using an abstract model which is also an abstract class.
In the subclass, I need to modify a field. This is done in the
__init_subclass__ method, by creating a field and adding it to the model
with ModelBase.add_to_class.
The field disappears from the class.

Doing exactly the same on a model which is not an abstract class works
fine.

see unittest file to reproduce this bug.

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

Django

unread,
Jul 17, 2023, 4:43:38 PM7/17/23
to django-...@googlegroups.com
#34719: modelBase.add_to_class is ineffective when called in __init_subclass__ of
an abstract Model
-------------------------------------+-------------------------------------
Reporter: piscvau | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: dynamic model | Triage Stage:
modification | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* Attachment "tests_abcmodel_bug.py" added.

unittest test file to reproduce

Django

unread,
Jul 17, 2023, 5:22:49 PM7/17/23
to django-...@googlegroups.com
#34719: modelBase.add_to_class is ineffective when called in __init_subclass__ of
an abstract Model
-------------------------------------+-------------------------------------
Reporter: piscvau | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: dynamic model | Triage Stage:
modification | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #34555.

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

Reply all
Reply to author
Forward
0 new messages