Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure add_stator_indexes only run for direct descendants of StatorModel #696

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion stator/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ def add_stator_indexes(sender, **kwargs):
Inject Indexes used by StatorModel in to any subclasses. This sidesteps the
current Django inability to inherit indexes when the Model subclass defines
its own indexes.

We should only add this for models that direct descendants of
StatorModel, otherwise we will see system check errors.
"""
if issubclass(sender, StatorModel):
if sender.__base__ is StatorModel:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not completely thrilled with this--__base__ is semi-documented, and points to the first parent class.

But I'm not sure what multiple inheritance would do in the context of Django models.

indexes = [
models.Index(
fields=["state", "state_next_attempt", "state_locked_until"],
Expand Down
Loading