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

Specify ignored attributes in mappings #1927

Closed
lunalucadou opened this issue Oct 7, 2024 · 1 comment · Fixed by #1936
Closed

Specify ignored attributes in mappings #1927

lunalucadou opened this issue Oct 7, 2024 · 1 comment · Fixed by #1936

Comments

@lunalucadou
Copy link

SQLAlchemy interprets the ClassVar type annotation to mean a non-mapped variable which the ORM can safely ignore. This is great, since it lets us populate special fields at runtime without IDEs complaining about unresolved attributes (and, if the value is read before being set, it doesn't risk causing a runtime exception).

Is there a way to emulate this with Document mappings? We could pre-populate the fields to be empty strs/lists/dicts, but that means re-building our indices every time we want to add/remove special attributes or change their types.

@miguelgrinberg
Copy link
Collaborator

There is no way to do this currently, but using ClassVar for such attributes would work. I'll look into it.

miguelgrinberg added a commit to miguelgrinberg/elasticsearch-dsl-py that referenced this issue Nov 5, 2024
github-actions bot pushed a commit that referenced this issue Nov 6, 2024
* Do not map ClassVar attributes

Fixes #1927

* document ClassVar usage

(cherry picked from commit 47a7a06)
miguelgrinberg added a commit that referenced this issue Nov 6, 2024
* Do not map ClassVar attributes

Fixes #1927

* document ClassVar usage

(cherry picked from commit 47a7a06)

Co-authored-by: Miguel Grinberg <[email protected]>
miguelgrinberg added a commit to miguelgrinberg/elasticsearch-dsl-py that referenced this issue Dec 9, 2024
* Do not map ClassVar attributes

Fixes elastic#1927

* document ClassVar usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants