Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#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 Carlton Gibson, 4 years ago

Triage Stage: UnreviewedAccepted

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.

comment:2 by Shipeng Feng, 4 years ago

Owner: changed from nobody to Shipeng Feng
Status: newassigned

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 8058d9d7:

Fixed #30955 -- Doc'd that only concrete base models are stored in historical models bases.

Abstract models are removed from bases when generating historical model
state since 6436f1fad9ce51f18735106ac75aeea3d6d1f310.

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 59578eba:

[3.0.x] Fixed #30955 -- Doc'd that only concrete base models are stored in historical models bases.

Abstract models are removed from bases when generating historical model
state since 6436f1fad9ce51f18735106ac75aeea3d6d1f310.
Backport of 8058d9d7adb189fec75a4b57565f225996c7b22c from master

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 5ad97e5:

[2.2.x] Fixed #30955 -- Doc'd that only concrete base models are stored in historical models bases.

Abstract models are removed from bases when generating historical model
state since 6436f1fad9ce51f18735106ac75aeea3d6d1f310.

Backport of 8058d9d7adb189fec75a4b57565f225996c7b22c from master.

Note: See TracTickets for help on using tickets.
Back to Top