Skip to content

Commit 4441da0

Browse files
authored
Use ElasticsearchWarning instead of ElasticsearchDeprecationWarning
1 parent dc26809 commit 4441da0

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

elasticsearch/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
ConnectionTimeout,
5252
AuthenticationException,
5353
AuthorizationException,
54+
ElasticsearchWarning,
5455
ElasticsearchDeprecationWarning,
5556
)
5657

@@ -80,6 +81,7 @@
8081
"ConnectionTimeout",
8182
"AuthenticationException",
8283
"AuthorizationException",
84+
"ElasticsearchWarning",
8385
"ElasticsearchDeprecationWarning",
8486
]
8587

elasticsearch/connection/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from ..exceptions import (
3232
TransportError,
3333
ImproperlyConfigured,
34-
ElasticsearchDeprecationWarning,
34+
ElasticsearchWarning,
3535
HTTP_EXCEPTIONS,
3636
)
3737
from .. import __versionstr__
@@ -197,7 +197,7 @@ def _raise_warnings(self, warning_headers):
197197
warning_messages.append(header)
198198

199199
for message in warning_messages:
200-
warnings.warn(message, category=ElasticsearchDeprecationWarning)
200+
warnings.warn(message, category=ElasticsearchWarning)
201201

202202
def _pretty_json(self, data):
203203
# pretty JSON in tracer curl logs

elasticsearch/exceptions.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,18 @@ class AuthorizationException(TransportError):
153153
""" Exception representing a 403 status code. """
154154

155155

156-
class ElasticsearchDeprecationWarning(Warning):
156+
class ElasticsearchWarning(Warning):
157157
"""Warning that is raised when a deprecated option
158-
is flagged via the 'Warning' HTTP header.
158+
or incorrect usage is flagged via the 'Warning' HTTP header.
159159
"""
160160

161161

162+
# Alias of 'ElasticsearchWarning' for backwards compatibility.
163+
# Additional functionality was added to the 'Warning' HTTP header
164+
# not related to deprecations.
165+
ElasticsearchDeprecationWarning = ElasticsearchWarning
166+
167+
162168
# more generic mappings from status_code to python exceptions
163169
HTTP_EXCEPTIONS = {
164170
400: RequestError,

elasticsearch/exceptions.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class ConflictError(TransportError): ...
4343
class RequestError(TransportError): ...
4444
class AuthenticationException(TransportError): ...
4545
class AuthorizationException(TransportError): ...
46-
class ElasticsearchDeprecationWarning(Warning): ...
46+
class ElasticsearchWarning(Warning): ...
47+
48+
ElasticsearchDeprecationWarning = ElasticsearchWarning
4749

4850
HTTP_EXCEPTIONS: Dict[int, ElasticsearchException]

test_elasticsearch/test_async/test_server/test_rest_api_spec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import warnings
2525
import inspect
2626

27-
from elasticsearch import RequestError, ElasticsearchDeprecationWarning
27+
from elasticsearch import RequestError, ElasticsearchWarning
2828
from elasticsearch.helpers.test import _get_version
2929
from ...test_server.test_rest_api_spec import (
3030
YamlRunner,
@@ -111,7 +111,7 @@ async def run_do(self, action):
111111
for k in args:
112112
args[k] = self._resolve(args[k])
113113

114-
warnings.simplefilter("always", category=ElasticsearchDeprecationWarning)
114+
warnings.simplefilter("always", category=ElasticsearchWarning)
115115
with warnings.catch_warnings(record=True) as caught_warnings:
116116
try:
117117
self.last_response = await api(**args)
@@ -129,7 +129,7 @@ async def run_do(self, action):
129129
caught_warnings = [
130130
str(w.message)
131131
for w in caught_warnings
132-
if w.category == ElasticsearchDeprecationWarning
132+
if w.category == ElasticsearchWarning
133133
and str(w.message) not in allowed_warnings
134134
]
135135

test_elasticsearch/test_server/test_rest_api_spec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import warnings
3030
import pytest
3131

32-
from elasticsearch import TransportError, RequestError, ElasticsearchDeprecationWarning
32+
from elasticsearch import TransportError, RequestError, ElasticsearchWarning
3333
from elasticsearch.compat import string_types
3434
from elasticsearch.helpers.test import _get_version
3535

@@ -146,7 +146,7 @@ def run_do(self, action):
146146
for k in args:
147147
args[k] = self._resolve(args[k])
148148

149-
warnings.simplefilter("always", category=ElasticsearchDeprecationWarning)
149+
warnings.simplefilter("always", category=ElasticsearchWarning)
150150
with warnings.catch_warnings(record=True) as caught_warnings:
151151
try:
152152
self.last_response = api(**args)
@@ -164,7 +164,7 @@ def run_do(self, action):
164164
caught_warnings = [
165165
str(w.message)
166166
for w in caught_warnings
167-
if w.category == ElasticsearchDeprecationWarning
167+
if w.category == ElasticsearchWarning
168168
and str(w.message) not in allowed_warnings
169169
]
170170

0 commit comments

Comments
 (0)