Skip to content

Commit

Permalink
fix: pin elasticsearch-py bellow 7.14 (#71)
Browse files Browse the repository at this point in the history
* fix: pin elasticsearch-py bellow 7.14

* bump requirements.txt

* fix mypy with elasticsearch > 7.10
  • Loading branch information
dpgaspar authored Sep 30, 2021
1 parent 02959e9 commit 634afd4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
10 changes: 6 additions & 4 deletions es/baseapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(
self.cursors: List[BaseCursor] = []
self.kwargs = kwargs
# Subclass needs to initialize Elasticsearch
self.es = None
self.es: Optional[Elasticsearch] = None

@check_closed
def close(self):
Expand Down Expand Up @@ -320,9 +320,11 @@ def elastic_query(self, query: str) -> Dict[str, Any]:
except es_exceptions.ConnectionError:
raise exceptions.OperationalError("Error connecting to Elasticsearch")
except es_exceptions.RequestError as ex:
raise exceptions.ProgrammingError(
f"Error ({ex.error}): {ex.info['error']['reason']}"
)
raise exceptions.ProgrammingError(f"Error ({ex.error}): {ex.info}")
# When method is HEAD and code is 404 perform request returns True
# So response is Union[bool, Any]
if isinstance(response, bool):
raise exceptions.UnexpectedRequestResponse()
# Opendistro errors are http status 200
if "error" in response:
raise exceptions.ProgrammingError(
Expand Down
12 changes: 6 additions & 6 deletions es/elastic/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ def __init__(
@check_closed
def cursor(self) -> BaseCursor:
"""Return a new Cursor Object using the connection."""
cursor = Cursor(self.url, self.es, **self.kwargs)
self.cursors.append(cursor)
return cursor
if self.es:
cursor = Cursor(self.url, self.es, **self.kwargs)
self.cursors.append(cursor)
return cursor
raise exceptions.UnexpectedESInitError()


class Cursor(BaseCursor):
Expand Down Expand Up @@ -165,9 +167,7 @@ def get_array_type_columns(self, table_name: str) -> "Cursor":
f"Error connecting to {self.url}: {e.info}"
)
except es_exceptions.NotFoundError as e:
raise exceptions.ProgrammingError(
f"Error ({e.error}): {e.info['error']['reason']}"
)
raise exceptions.ProgrammingError(f"Error ({e.error}): {e.info}")
try:
if response["hits"]["total"]["value"] == 0:
source = {}
Expand Down
12 changes: 11 additions & 1 deletion es/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Error(Exception):
pass
"""Base exception"""


class Warning(Exception):
Expand Down Expand Up @@ -36,3 +36,13 @@ class DataError(DatabaseError):

class NotSupportedError(DatabaseError):
pass


class UnexpectedESInitError(Error):
""" Should never happen, when a cursor is requested
without an ElasticSearch object being initialized"""


class UnexpectedRequestResponse(Error):
""" When perform request returns False, only when HTTP method HEAD
and status code 404 """
8 changes: 5 additions & 3 deletions es/opendistro/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ def _aws_auth(aws_access_key: str, aws_secret_key: str, region: str) -> Any:
@check_closed
def cursor(self) -> "Cursor":
"""Return a new Cursor Object using the connection."""
cursor = Cursor(self.url, self.es, **self.kwargs)
self.cursors.append(cursor)
return cursor
if self.es:
cursor = Cursor(self.url, self.es, **self.kwargs)
self.cursors.append(cursor)
return cursor
raise exceptions.UnexpectedESInitError()


class Cursor(BaseCursor):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# pip-compile
#
elasticsearch==7.0.5
elasticsearch==7.13.4
# via elasticsearch-dbapi (setup.py)
greenlet==1.0.0
# via sqlalchemy
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"odelasticsearch.https = es.opendistro.sqlalchemy:ESHTTPSDialect",
]
},
install_requires=["elasticsearch>7", "packaging==21.0", "sqlalchemy"],
install_requires=["elasticsearch>7, <7.14", "packaging==21.0", "sqlalchemy"],
extras_require={"opendistro": ["requests_aws4auth", "boto3"]},
author="Preset Inc.",
author_email="[email protected]",
Expand Down

0 comments on commit 634afd4

Please sign in to comment.