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

Tasks API failing with 8.17.1 (but not 8.15.2) #2765

Open
untergeek opened this issue Jan 24, 2025 · 3 comments
Open

Tasks API failing with 8.17.1 (but not 8.15.2) #2765

untergeek opened this issue Jan 24, 2025 · 3 comments
Labels
Area: Client Manually written code that fits in no other area Category: Question

Comments

@untergeek
Copy link
Member

Problem call:

        taskid = 'um92aFeET6uhTTztmds6QQ:1548121'
        response = None
        try:
            response = client.tasks.get(task_id=taskid)
        except Exception as err:
            msg = (
                f'Unable to obtain task information for task_id "{taskid}". '
                f'Response: {response} -- '
                f'Exception: {err}'
            )
            raise ValueError(msg) from err

This call works fine in 8.15.2. But attempting the same in 8.17.1 raises an unknown exception and warning:

Unable to obtain task information for task_id "um92aFeET6uhTTztmds6QQ:1548121". Response:
None -- Exception:
GeneralAvailabilityWarning('This API is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.')

Not sure what's going on, but something that was working no longer is. Affected versions may include any between 8.15.2 and 8.17.1.

@untergeek
Copy link
Member Author

Confirmed this also occurs in 8.16.0, so ostensibly every version between 8.16.0 and 8.17.1 is affected.

@pquentin
Copy link
Member

Hello @untergeek, and thanks for opening this issue! As mentioned in the release notes, elasticsearch-py 8.16.0 and above emit warnings for tech preview and beta APIs. We added this because we did not want users to rely on such APIs without knowing they were not GA yet. Indeed, as of Elasticsearch 8.17, the tasks APIs are still in tech preview.

However, the client code only emits a warning by using this decorator. Python allows turning warnings into exceptions, but it has to be explicitly configured to do so. The client is not doing this:

# Only raise one warning per deprecation message so as not
# to spam up the user if the same action is done multiple times.
warnings.simplefilter("default", category=ElasticsearchWarning, append=True)

(If it were error instead of default, it would raise an exception. See docs.python.org/3/library/warnings.html#the-warnings-filter for more details.) But pytest can override this setting, for example, and maybe python -Wall does it too? Not sure. In any case, I believe this issue is a duplicate of #2742.

@pquentin pquentin added Area: Client Manually written code that fits in no other area Category: Question labels Jan 25, 2025
untergeek added a commit to untergeek/es-wait that referenced this issue Jan 27, 2025
See [the 8.16.0 Python client release notes](https://github.com/elastic/elasticsearch-py/releases/tag/v8.16.0) for the workaround.

This exact fix is included now in src/es_wait/task.py

I had initially raised an issue at elastic/elasticsearch-py#2765 to learn what transpired.

```diff
--- a/src/es_wait/task.py
+++ b/src/es_wait/task.py
@@ -2,8 +2,10 @@

 import typing as t
 import logging
+import warnings
 from time import localtime, strftime
 from dotmap import DotMap  # type: ignore
+from elasticsearch8.exceptions import GeneralAvailabilityWarning
 from ._base import Waiter

 if t.TYPE_CHECKING:
@@ -72,6 +74,10 @@ class Task(Waiter):

         response = {}
         try:
+            # The Tasks API is not yet GA. We need to suppress the warning for now.
+            # This is required after elasticsearch8>=8.16.0 as the warning is raised
+            # from that release onward.
+            warnings.filterwarnings("ignore", category=GeneralAvailabilityWarning)
             response = dict(self.client.tasks.get(task_id=self.task_id))
         except Exception as err:
             msg = (
```
@untergeek
Copy link
Member Author

Thank you for the context. This is indeed what I was bit by, but with it being the GeneralAvailabilityWarning instead.

The workaround in the release notes did the trick. This issue can be closed, or left open for others to find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Client Manually written code that fits in no other area Category: Question
Projects
None yet
Development

No branches or pull requests

2 participants