Skip to content

Commit

Permalink
Finally found the Tasks API warning bug
Browse files Browse the repository at this point in the history
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 = (
```
  • Loading branch information
untergeek committed Jan 27, 2025
1 parent e945ca5 commit 6883245
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/es_wait/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Top-level init file"""

__version__ = '0.9.2'
__version__ = '0.9.3'
from .exists import Exists
from .health import Health
from .index import Index
Expand Down
6 changes: 6 additions & 0 deletions src/es_wait/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -72,6 +74,10 @@ def check(self) -> bool:

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 = (
Expand Down

0 comments on commit 6883245

Please sign in to comment.