#30955 closed Cleanup/optimization (fixed)
Document the different behavior of migration historical models while they have abstract base classes.
Reported by: | Shipeng Feng | Owned by: | Shipeng Feng |
---|---|---|---|
Component: | Documentation | Version: | 2.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
In the documentation of migrations, we have:
In addition, the base classes of the model are just stored as pointers, so you must always keep base classes
around for as long as there is a migration that contains a reference to them. On the plus side, methods and
managers from these base classes inherit normally, so if you absolutely need access to these you can opt to move
them into a superclass.
However, this is not the case for abstract base classes, for example:
class ModelMixin(object): def method_in_mixin(self): pass class BaseModel(ModelMixin, models.Model): class Meta: abstract = True create_time = models.DateTimeField(db_column='create_time', auto_now_add=True) def method_in_abstract(self): pass
In historical models, we can access method_in_mixin
, but we can not access method_in_abstract
.
I have a look at the source code and find out that abstract base classes won't appear in the bases of the
historical model.
If this is the desired behavior, I'd like it to be documented:
In addition, the base classes (excluding abstract base classes) of the model are just stored as pointers, so
you must always keep base classes...
If this is the right solution, I'd love to open a pull request to fix the docs.
Change History (6)
comment:1 by , 5 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
OK, yes, abstract models are removed from
bases
when generating historical model state since 6436f1fad9ce51f18735106ac75aeea3d6d1f310.I'm thinking maybe just "In addition, the concrete base classes …" might be enough.