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

Removed __orig_class__ attribute out of AttrDict instances #1877

Merged

Conversation

miguelgrinberg
Copy link
Collaborator

Fixes #1876

This change addressed a regression introduced in 8.15.0 as part of the refactor to support type hints.

The problem is in AttrDict, which can get confused and inject an attribute named __orig_class__ in the underlying dict. For example:

>>> from typing import Any
>>> from elasticsearch_dsl import AttrDict
>>> d = AttrDict[Any]({})
>>> d.to_dict()
{'__orig_class__': elasticsearch_dsl.utils.AttrDict[typing.Any]}

This happens because Python adds the __orig_class__ attribute to all instances that were created with explicit generic arguments given. The logic in AttrDict.__setattr__ to detect if an attribute is part of the dictionary or a real attribute of the instance does not work for __orig_class__.

@miguelgrinberg miguelgrinberg added the backport 8.x Backport to 8.x label Aug 13, 2024
@miguelgrinberg miguelgrinberg force-pushed the filter-orig-class-attribute branch from 1c69cd1 to e5c4556 Compare August 13, 2024 18:39
Copy link
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM. I see #1878 fixes the CI.

@miguelgrinberg miguelgrinberg force-pushed the filter-orig-class-attribute branch from e5c4556 to 14dac45 Compare August 15, 2024 11:48
@miguelgrinberg miguelgrinberg merged commit ec60616 into elastic:main Aug 15, 2024
16 checks passed
@miguelgrinberg miguelgrinberg deleted the filter-orig-class-attribute branch August 15, 2024 13:28
github-actions bot pushed a commit that referenced this pull request Aug 15, 2024
miguelgrinberg added a commit that referenced this pull request Aug 15, 2024
…1880)

(cherry picked from commit ec60616)

Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
@miguelgrinberg miguelgrinberg mentioned this pull request Aug 19, 2024
miguelgrinberg added a commit to miguelgrinberg/elasticsearch-dsl-py that referenced this pull request Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 8.x Backport to 8.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v8.15.0 breaks things related to type hints?
2 participants