Skip to content

Commit

Permalink
Merge pull request #855 from weaviate/fix-client-is-ready
Browse files Browse the repository at this point in the history
Fix client is ready
  • Loading branch information
dirkkul authored Feb 5, 2024
2 parents b1b75ab + ac82a8a commit 00ec1ff
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
15 changes: 15 additions & 0 deletions integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,18 @@ def test_client_error_for_wcs_without_auth() -> None:
with pytest.raises(weaviate.exceptions.AuthenticationFailedError) as e:
weaviate.connect_to_wcs(cluster_url=WCS_URL, auth_credentials=None)
assert "wvc.init.Auth.api_key" in e.value.message


def test_client_is_not_ready() -> None:
assert not weaviate.WeaviateClient(
connection_params=weaviate.connect.ConnectionParams.from_url(
"http://localhost:8080", 50051
),
skip_init_checks=True,
).is_ready()


def test_client_is_ready() -> None:
assert weaviate.connect_to_wcs(
cluster_url=WCS_URL, auth_credentials=WCS_CREDS, skip_init_checks=True
).is_ready()
33 changes: 22 additions & 11 deletions weaviate/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

from typing import Generic, Optional, Tuple, TypeVar, Union, Dict, Any

from httpx import ConnectError as HTTPXConnectError
from httpx import HTTPError as HttpxError
from requests.exceptions import ConnectionError as RequestsConnectionError

from weaviate.backup.backup import _Backup
from weaviate.collections.classes.internal import _GQLEntryReturnType, _RawGQLReturn

from weaviate.validator import _ValidateArgument, _validate_input
from .auth import AuthCredentials
from .backup import Backup
from .batch import Batch
Expand All @@ -26,14 +25,20 @@
ProtocolParams,
TIMEOUT_TYPE_RETURN,
)
from .connect.v4 import _ExpectedStatusCodes
from .contextionary import Contextionary
from .data import DataObject
from .embedded import EmbeddedV3, EmbeddedV4, EmbeddedOptions
from .exceptions import UnexpectedStatusCodeError
from .exceptions import (
UnexpectedStatusCodeError,
WeaviateClosedClientError,
WeaviateConnectionError,
)
from .gql import Query
from .schema import Schema
from .types import NUMBER
from .util import _decode_json_response_dict, _get_valid_timeout_config, _type_request_response
from .validator import _validate_input, _ValidateArgument
from .warnings import _Warnings

TIMEOUT_TYPE = Union[Tuple[NUMBER, NUMBER], NUMBER]
Expand All @@ -59,7 +64,13 @@ def is_ready(self) -> bool:
if response.status_code == 200:
return True
return False
except RequestsConnectionError:
except (
HttpxError,
RequestsConnectionError,
UnexpectedStatusCodeError,
WeaviateClosedClientError,
WeaviateConnectionError,
):
return False

def is_live(self) -> bool:
Expand Down Expand Up @@ -306,16 +317,16 @@ def graphql_raw_query(self, gql_query: str) -> _RawGQLReturn:
`weaviate.UnexpectedStatusCodeError`
If weaviate reports a none OK status.
"""

if not isinstance(gql_query, str):
raise TypeError("Query is expected to be a string")
_validate_input(_ValidateArgument([str], "gql_query", gql_query))

json_query = {"query": gql_query}

try:
response = self._connection.post(path="/graphql", weaviate_object=json_query)
except HTTPXConnectError as conn_err:
raise HTTPXConnectError("Query not executed.") from conn_err
response = self._connection.post(
path="/graphql",
weaviate_object=json_query,
error_msg="Raw GQL query failed",
status_codes=_ExpectedStatusCodes(ok_in=[200], error="GQL query"),
)

res = _decode_json_response_dict(response, "GQL query")
assert res is not None
Expand Down

0 comments on commit 00ec1ff

Please sign in to comment.