Skip to content

v8.15.0 breaks things related to type hints? #1876

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

Closed
jgb opened this issue Aug 12, 2024 · 5 comments · Fixed by #1877
Closed

v8.15.0 breaks things related to type hints? #1876

jgb opened this issue Aug 12, 2024 · 5 comments · Fixed by #1877

Comments

@jgb
Copy link

jgb commented Aug 12, 2024

Hello,

some of my existing code breaks when upgrading from v8.14.0 to v8.15.0 as follows:

self = elasticsearch_dsl.utils.AttrDict[typing.Any], attr = 'doc_count'

    def __getattr__(self, attr):
        if attr in {'__name__', '__qualname__'}:
            return self._name or self.__origin__.__name__

        # We are careful for copy and pickle.
        # Also for simplicity we don't relay any dunder names
        if '__origin__' in self.__dict__ and not _is_dunder(attr):
>           return getattr(self.__origin__, attr)
E           AttributeError: type object 'AttrDict' has no attribute 'doc_count'

/usr/lib/python3.12/typing.py:1185: AttributeError

Greetings,

jgb

@miguelgrinberg
Copy link
Collaborator

I'm not sure how this could have happened. Can you also show me your code?

@jgb
Copy link
Author

jgb commented Aug 12, 2024

search.aggs.bucket("filters", "filters", filters=filters)

results = search.execute().aggregations.filters.buckets.to_dict()
watcher_counts_via_filters_agg = [v.doc_count for k, v in sorted(results.items())]

It's the doc_count from the last line that triggers the error from my original post.
The code works fine on 8.14.0 (and before) but breaks in 8.15.0.
Downgrading fixes it.

Different side effect for the same issue happens in one other part of our code (these are all pytests by the way):

    result = search.execute()
    assert result.aggs == {
        "gender_1": {
            "avg_attention": {"value": 40.0},
            "doc_count": 2,
        },
    }

The assert fails here because doc_count is gone with elasticsearch_dsl >= 8.15.0.

Greetings,

jgb

@miguelgrinberg
Copy link
Collaborator

Okay, I need to investigate this. A lot of our testing is based on bucket aggregations that are returned as a list, and those do have the doc_count. I'm going to build a new test that uses the object format for the buckets, it seems we have a testing hole there and for that reason I guess it is possible that something broke.

@miguelgrinberg
Copy link
Collaborator

miguelgrinberg commented Aug 15, 2024

I expect we'll be releasing 8.15.1 with this fix next week. In the meantime, if you'd like to verify the fix please install the main branch directly from this repository.

@jgb
Copy link
Author

jgb commented Aug 16, 2024

I expect we'll be releasing 8.15.1 with this fix next week. In the meantime, if you'd like to verify the fix please install the main branch directly from this repository.

I just tested the main branch like you said, and it indeed fixes the errors I was having.
Thanks a lot!

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 a pull request may close this issue.

2 participants