Skip to content

Commit

Permalink
Use ElasticsearchWarning instead of ElasticsearchDeprecationWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson authored Jan 4, 2021
1 parent dc26809 commit 4441da0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions elasticsearch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
ConnectionTimeout,
AuthenticationException,
AuthorizationException,
ElasticsearchWarning,
ElasticsearchDeprecationWarning,
)

Expand Down Expand Up @@ -80,6 +81,7 @@
"ConnectionTimeout",
"AuthenticationException",
"AuthorizationException",
"ElasticsearchWarning",
"ElasticsearchDeprecationWarning",
]

Expand Down
4 changes: 2 additions & 2 deletions elasticsearch/connection/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ..exceptions import (
TransportError,
ImproperlyConfigured,
ElasticsearchDeprecationWarning,
ElasticsearchWarning,
HTTP_EXCEPTIONS,
)
from .. import __versionstr__
Expand Down Expand Up @@ -197,7 +197,7 @@ def _raise_warnings(self, warning_headers):
warning_messages.append(header)

for message in warning_messages:
warnings.warn(message, category=ElasticsearchDeprecationWarning)
warnings.warn(message, category=ElasticsearchWarning)

def _pretty_json(self, data):
# pretty JSON in tracer curl logs
Expand Down
10 changes: 8 additions & 2 deletions elasticsearch/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,18 @@ class AuthorizationException(TransportError):
""" Exception representing a 403 status code. """


class ElasticsearchDeprecationWarning(Warning):
class ElasticsearchWarning(Warning):
"""Warning that is raised when a deprecated option
is flagged via the 'Warning' HTTP header.
or incorrect usage is flagged via the 'Warning' HTTP header.
"""


# Alias of 'ElasticsearchWarning' for backwards compatibility.
# Additional functionality was added to the 'Warning' HTTP header
# not related to deprecations.
ElasticsearchDeprecationWarning = ElasticsearchWarning


# more generic mappings from status_code to python exceptions
HTTP_EXCEPTIONS = {
400: RequestError,
Expand Down
4 changes: 3 additions & 1 deletion elasticsearch/exceptions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ConflictError(TransportError): ...
class RequestError(TransportError): ...
class AuthenticationException(TransportError): ...
class AuthorizationException(TransportError): ...
class ElasticsearchDeprecationWarning(Warning): ...
class ElasticsearchWarning(Warning): ...

ElasticsearchDeprecationWarning = ElasticsearchWarning

HTTP_EXCEPTIONS: Dict[int, ElasticsearchException]
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import warnings
import inspect

from elasticsearch import RequestError, ElasticsearchDeprecationWarning
from elasticsearch import RequestError, ElasticsearchWarning
from elasticsearch.helpers.test import _get_version
from ...test_server.test_rest_api_spec import (
YamlRunner,
Expand Down Expand Up @@ -111,7 +111,7 @@ async def run_do(self, action):
for k in args:
args[k] = self._resolve(args[k])

warnings.simplefilter("always", category=ElasticsearchDeprecationWarning)
warnings.simplefilter("always", category=ElasticsearchWarning)
with warnings.catch_warnings(record=True) as caught_warnings:
try:
self.last_response = await api(**args)
Expand All @@ -129,7 +129,7 @@ async def run_do(self, action):
caught_warnings = [
str(w.message)
for w in caught_warnings
if w.category == ElasticsearchDeprecationWarning
if w.category == ElasticsearchWarning
and str(w.message) not in allowed_warnings
]

Expand Down
6 changes: 3 additions & 3 deletions test_elasticsearch/test_server/test_rest_api_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import warnings
import pytest

from elasticsearch import TransportError, RequestError, ElasticsearchDeprecationWarning
from elasticsearch import TransportError, RequestError, ElasticsearchWarning
from elasticsearch.compat import string_types
from elasticsearch.helpers.test import _get_version

Expand Down Expand Up @@ -146,7 +146,7 @@ def run_do(self, action):
for k in args:
args[k] = self._resolve(args[k])

warnings.simplefilter("always", category=ElasticsearchDeprecationWarning)
warnings.simplefilter("always", category=ElasticsearchWarning)
with warnings.catch_warnings(record=True) as caught_warnings:
try:
self.last_response = api(**args)
Expand All @@ -164,7 +164,7 @@ def run_do(self, action):
caught_warnings = [
str(w.message)
for w in caught_warnings
if w.category == ElasticsearchDeprecationWarning
if w.category == ElasticsearchWarning
and str(w.message) not in allowed_warnings
]

Expand Down

0 comments on commit 4441da0

Please sign in to comment.