Restore and deprecate client.tasks.get() without task_id
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import warnings
|
||||
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
|
||||
|
||||
|
||||
@@ -58,7 +59,7 @@ class TasksClient(NamespacedClient):
|
||||
)
|
||||
|
||||
@query_params("timeout", "wait_for_completion")
|
||||
def get(self, task_id, params=None, headers=None):
|
||||
def get(self, task_id=None, params=None, headers=None):
|
||||
"""
|
||||
Returns information about a task.
|
||||
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html>`_
|
||||
@@ -70,7 +71,11 @@ class TasksClient(NamespacedClient):
|
||||
complete (default: false)
|
||||
"""
|
||||
if task_id in SKIP_IN_PATH:
|
||||
raise ValueError("Empty value passed for a required argument 'task_id'.")
|
||||
warnings.warn(
|
||||
"Calling client.tasks.get() without a task_id is deprecated "
|
||||
"and will be removed in v8.0. Use client.tasks.list() instead.",
|
||||
DeprecationWarning,
|
||||
)
|
||||
|
||||
return self.transport.perform_request(
|
||||
"GET", _make_path("_tasks", task_id), params=params, headers=headers
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
import warnings
|
||||
|
||||
from elasticsearch.client import _normalize_hosts, Elasticsearch
|
||||
|
||||
@@ -110,3 +111,27 @@ class TestClient(ElasticsearchTestCase):
|
||||
self.client.index(index="my-index", id=0, body={})
|
||||
|
||||
self.assert_url_called("PUT", "/my-index/_doc/0")
|
||||
|
||||
def test_tasks_get_without_task_id_deprecated(self):
|
||||
warnings.simplefilter("always", DeprecationWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
self.client.tasks.get()
|
||||
|
||||
self.assert_url_called("GET", "/_tasks")
|
||||
self.assertEquals(len(w), 1)
|
||||
self.assertIs(w[0].category, DeprecationWarning)
|
||||
self.assertEquals(
|
||||
str(w[0].message),
|
||||
"Calling client.tasks.get() without a task_id is deprecated "
|
||||
"and will be removed in v8.0. Use client.tasks.list() instead.",
|
||||
)
|
||||
|
||||
def test_tasks_get_with_task_id_not_deprecated(self):
|
||||
warnings.simplefilter("always", DeprecationWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
self.client.tasks.get("task-1")
|
||||
self.client.tasks.get(task_id="task-2")
|
||||
|
||||
self.assert_url_called("GET", "/_tasks/task-1")
|
||||
self.assert_url_called("GET", "/_tasks/task-2")
|
||||
self.assertEquals(len(w), 0)
|
||||
|
||||
@@ -146,6 +146,13 @@ class API:
|
||||
p in url.get("parts", {}) for url in self._def["url"]["paths"]
|
||||
)
|
||||
|
||||
# This piece of logic corresponds to calling
|
||||
# client.tasks.get() w/o a task_id which was erroneously
|
||||
# allowed in the 7.1 client library. This functionality
|
||||
# is deprecated and will be removed in 8.x.
|
||||
if self.namespace == "tasks" and self.name == "get":
|
||||
parts["task_id"]["required"] = False
|
||||
|
||||
for k, sub in SUBSTITUTIONS.items():
|
||||
if k in parts:
|
||||
parts[sub] = parts.pop(k)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{% extends "base" %}
|
||||
{% block request %}
|
||||
if task_id in SKIP_IN_PATH:
|
||||
warnings.warn(
|
||||
"Calling client.tasks.get() without a task_id is deprecated "
|
||||
"and will be removed in v8.0. Use client.tasks.list() instead.",
|
||||
DeprecationWarning,
|
||||
)
|
||||
|
||||
{{ super()|trim }}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user