Skip to content
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

Fix client is ready #855

Merged
merged 6 commits into from
Feb 5, 2024
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
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
Loading