Skip to content

Add system check for LifecycleModelMixin coming after models.Model - #187

Open
juneja-varun wants to merge 1 commit into
rsinger86:masterfrom
juneja-varun:add-lifecycle-mixin-mro-check
Open

Add system check for LifecycleModelMixin coming after models.Model#187
juneja-varun wants to merge 1 commit into
rsinger86:masterfrom
juneja-varun:add-lifecycle-mixin-mro-check

Conversation

@juneja-varun

Copy link
Copy Markdown

Fixes #149.

If `models.Model` comes before `LifecycleModelMixin` in a model's base classes, `Model.save()` wins the MRO and runs instead of the mixin's - so every lifecycle hook on that model silently never fires. No error, no warning, hooks just don't run. Confirmed this live: a model with the bases swapped saves fine, but a `BEFORE_SAVE` hook that should flip a field never does.

Added a new check (`django_lifecycle.E002`) alongside the existing one, following the direction discussed in #147 - flags any model using `LifecycleModelMixin` where it doesn't come before `models.Model` in the MRO, so this fails loudly (via `manage.py check`) instead of silently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve django check by checking if LifecycleModelMixin precedes models.Model in the MRO

1 participant