-
Notifications
You must be signed in to change notification settings - Fork 435
Initialize indexes in the model metaclass. #994
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
Conversation
""" | ||
Initialize indexes on the class. | ||
""" | ||
cls._indexes = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes current behavior where child classes now each have their own index dictionary instead of defaulting to the dictionary on the parent class.
b7c9793
to
1b2eda4
Compare
index.Meta.model = cls | ||
if not hasattr(index.Meta, "index_name"): | ||
index.Meta.index_name = name | ||
cls._indexes[index.Meta.index_name] = index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This keeps the current broken behavior where you can have index name collisions.
cls._indexes = {} | ||
for name, index in getmembers(cls, lambda o: isinstance(o, Index)): | ||
if not hasattr(index.Meta, "model"): | ||
index.Meta.model = cls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the current behavior where the class is set by any model that has the index in the class namespace. Now first write wins.
This is a preliminary change to simplify index management before fixing #992.