Skip to content

Deprecation warnings in elasticsearch 8.12.0 with current version 8.12.0 of this library #1711

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
robinmuhia opened this issue Feb 28, 2024 · 9 comments

Comments

@robinmuhia
Copy link

robinmuhia commented Feb 28, 2024

The current latest version of elastic search -dsl has numerous deprecation warnings with regards to passing of the body parameter and transport options to elasticsearch. I am willing to contribute to fix the current implementation to match elasticsearch library's recommendations if no one is on it at the time. A snippet of such warnings is found below:

DeprecationWarning: The 'body' parameter is deprecated and will be removed in a future version. Instead use individual parameters.
    es.search(index=self._index, body=self.to_dict(), **self._params).body,
DeprecationWarning: Passing transport options in the API method is deprecated. Use 'Elasticsearch.options()' instead.
    return self._get_connection(using).indices.delete(index=self._name, **kwargs)

I have read the contributing guidelines which state i first have to open an issue before contributing.

@robinmuhia robinmuhia changed the title Deprecation warnings in elastic_search version 8.10.12 Deprecation warnings in elasticsearch 8.12.0 with current version 8.12.0 of this library Feb 28, 2024
@pquentin
Copy link
Member

pquentin commented Feb 28, 2024

Hey @robinmuhia, thanks for reading the guidelines and reaching out! I'm surprised about the body warnings you're seeing, because elasticsearch-py 8.12.0 actually removed this warning: the body parameter is supported, but should not be mixed with other body-like parameters.

In any case, yes, if the latest version of this library is emitting warnings, we need to fix them, and I'd appreciate your help. I think the best way to proceed forward is to write a test for each warning to prove that a warning is emitted. (The CI is designed to fail on warnings.) I fixed one already: 40e1632 but would be happy to fix the rest.

Does that make sense?

@robinmuhia
Copy link
Author

Thanks for the reply. I will work on it over the weekend and get back to you.

@pquentin
Copy link
Member

Sounds great! Please start with a single warning and share your work early to make sure it's the right direction to avoid wasted work.

@robinmuhia
Copy link
Author

robinmuhia commented Feb 29, 2024

Apologies. After further investigation, i realized pip was installing an older cached version and not the current 8.12.0. That explains the body warnings. But i still get the options warning. As seen below .

/python3.11/site-packages/elasticsearch_dsl/index.py:404: DeprecationWarning: Passing transport options in the API method is deprecated. Use 'Elasticsearch.options()' instead.
    return self._get_connection(using).indices.delete(index=self._name, **kwargs)

This specific line causes the warning

    def delete(self, using=None, **kwargs):
        """
        Deletes the index in elasticsearch.

        Any additional keyword arguments will be passed to
        ``Elasticsearch.indices.delete`` unchanged.
        """
        return self._get_connection(using).indices.delete(index=self._name, **kwargs)

My conftest.py has the following code that is called in between test cases so the delete part calls the function above.

from elasticsearch import Elasticsearch
@pytest.fixture(autouse=True)
def clear_elasticsearch_indices(settings):
    """
    Fixture to clear all Elasticsearch indices after each test case.
    """
    es = Elasticsearch(hosts=settings.ELASTICSEARCH_DSL["default"]["hosts"])

    indices = es.options().indices.get_alias(index="*").keys()

    for index_name in indices:
        es.options(ignore_status=[404,400]).indices.delete(index=index_name)
    yield

@pquentin
Copy link
Member

How can this be reproduced? Running the test using nox -s test-3.12 does not reproduce the issue for me.

Indeed, as you can see in clear_elasticsearch_indices, deleting is done by passing transport options as options(), with delete only getting called with index. So the warning should not be triggered.

That said, this issue made me realize that I had forgotten to stop ignoring body warnings when running tests, so I opened #1712.

@robinmuhia
Copy link
Author

I will make a mini project with similar implementation and get back to you

@pquentin
Copy link
Member

To be clear it is possible to pass transport options today to delete() and other functions. It will trigger a warning but it will be up to the user of the library to fix it.

@robinmuhia
Copy link
Author

Hey, I am getting back to you. After doing some deep dive into the issue, it was a third party library that was causing the issue so i will just close this issue. Thanks for your guidance.

@pquentin
Copy link
Member

pquentin commented Mar 4, 2024

Thank you for circling back! Glad I could help.

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

No branches or pull requests

2 participants