diff --git a/elasticsearch/__init__.py b/elasticsearch/__init__.py index ba340899..7dc7be74 100644 --- a/elasticsearch/__init__.py +++ b/elasticsearch/__init__.py @@ -51,6 +51,7 @@ from .exceptions import ( ConnectionTimeout, AuthenticationException, AuthorizationException, + ElasticsearchWarning, ElasticsearchDeprecationWarning, ) @@ -80,6 +81,7 @@ __all__ = [ "ConnectionTimeout", "AuthenticationException", "AuthorizationException", + "ElasticsearchWarning", "ElasticsearchDeprecationWarning", ] diff --git a/elasticsearch/connection/base.py b/elasticsearch/connection/base.py index b5630b76..ee2cbac0 100644 --- a/elasticsearch/connection/base.py +++ b/elasticsearch/connection/base.py @@ -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 diff --git a/elasticsearch/exceptions.py b/elasticsearch/exceptions.py index 5da15889..077edf40 100644 --- a/elasticsearch/exceptions.py +++ b/elasticsearch/exceptions.py @@ -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, diff --git a/elasticsearch/exceptions.pyi b/elasticsearch/exceptions.pyi index 8906b6ce..27ea277d 100644 --- a/elasticsearch/exceptions.pyi +++ b/elasticsearch/exceptions.pyi @@ -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] diff --git a/test_elasticsearch/test_async/test_server/test_rest_api_spec.py b/test_elasticsearch/test_async/test_server/test_rest_api_spec.py index 07802e18..ffddd454 100644 --- a/test_elasticsearch/test_async/test_server/test_rest_api_spec.py +++ b/test_elasticsearch/test_async/test_server/test_rest_api_spec.py @@ -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 ] diff --git a/test_elasticsearch/test_server/test_rest_api_spec.py b/test_elasticsearch/test_server/test_rest_api_spec.py index b7b18b9e..dd82e9d8 100644 --- a/test_elasticsearch/test_server/test_rest_api_spec.py +++ b/test_elasticsearch/test_server/test_rest_api_spec.py @@ -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 ]