Skip to content

Conversation

jpinner-lyft
Copy link
Contributor

This is a preliminary change to simplify index management before fixing #992.

"""
Initialize indexes on the class.
"""
cls._indexes = {}
Copy link
Contributor Author

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.

@jpinner-lyft jpinner-lyft force-pushed the clean-up-index-initialization branch from b7c9793 to 1b2eda4 Compare November 10, 2021 20:02
index.Meta.model = cls
if not hasattr(index.Meta, "index_name"):
index.Meta.index_name = name
cls._indexes[index.Meta.index_name] = index
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@jpinner-lyft jpinner-lyft merged commit f868e6d into master Nov 10, 2021
@jpinner-lyft jpinner-lyft deleted the clean-up-index-initialization branch November 10, 2021 23:34
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.

3 participants