[7.x] Use ElasticsearchWarning instead of ElasticsearchDeprecationWarning
Co-authored-by: Seth Michael Larson <seth.larson@elastic.co>
This commit is contained in:
co-authored by
Seth Michael Larson
parent
b1e7bd501b
commit
f9f6eac9f1
@@ -51,6 +51,7 @@ from .exceptions import (
|
||||
ConnectionTimeout,
|
||||
AuthenticationException,
|
||||
AuthorizationException,
|
||||
ElasticsearchWarning,
|
||||
ElasticsearchDeprecationWarning,
|
||||
)
|
||||
|
||||
@@ -80,6 +81,7 @@ __all__ = [
|
||||
"ConnectionTimeout",
|
||||
"AuthenticationException",
|
||||
"AuthorizationException",
|
||||
"ElasticsearchWarning",
|
||||
"ElasticsearchDeprecationWarning",
|
||||
]
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ except ImportError:
|
||||
from ..exceptions import (
|
||||
TransportError,
|
||||
ImproperlyConfigured,
|
||||
ElasticsearchDeprecationWarning,
|
||||
ElasticsearchWarning,
|
||||
HTTP_EXCEPTIONS,
|
||||
)
|
||||
from .. import __versionstr__
|
||||
@@ -197,7 +197,7 @@ class Connection(object):
|
||||
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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -24,7 +24,7 @@ import pytest
|
||||
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,
|
||||
@@ -111,7 +111,7 @@ class AsyncYamlRunner(YamlRunner):
|
||||
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)
|
||||
@@ -129,7 +129,7 @@ class AsyncYamlRunner(YamlRunner):
|
||||
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
|
||||
]
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import yaml
|
||||
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
|
||||
|
||||
@@ -147,7 +147,7 @@ class YamlRunner:
|
||||
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)
|
||||
@@ -165,7 +165,7 @@ class YamlRunner:
|
||||
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
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user