Skip to content

Use ElasticsearchWarning instead of ElasticsearchDeprecationWarning #1495

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

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -145,7 +145,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 @@ -163,7 +163,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