Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
tellet-q committed Dec 10, 2024
1 parent bc14c79 commit 628e09b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
8 changes: 6 additions & 2 deletions qdrant_client/async_qdrant_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from qdrant_client._pydantic_compat import construct
from qdrant_client.auth import BearerAuth
from qdrant_client.async_client_base import AsyncQdrantBase
from qdrant_client.common.version_check import is_versions_compatible, get_server_version
from qdrant_client.common.version_check import is_compatible, get_server_version
from qdrant_client.connection import get_async_channel as get_channel
from qdrant_client.conversions import common_types as types
from qdrant_client.conversions.common_types import get_args_subscribed
Expand Down Expand Up @@ -164,7 +164,11 @@ def __init__(
server_version = get_server_version(
self.rest_uri, self._rest_headers, self._rest_args.get("auth")
)
if not is_versions_compatible(client_version, server_version):
if not server_version:
warnings.warn(
f"Failed to obtain server version. Unable to check compatibility. Set check_version=False to skip version check."
)
elif not is_compatible(client_version, server_version):
warnings.warn(
f"Qdrant client version {client_version} is incompatible with server version {server_version}. Major versions should match and minor version difference must not exceed 1. Set check_version=False to skip version check."
)
Expand Down
19 changes: 12 additions & 7 deletions qdrant_client/common/version_check.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import warnings
from typing import Any, Optional
from collections import namedtuple
Expand All @@ -15,16 +16,20 @@ def get_server_version(
try:
response = httpx.get(rest_uri + "/", headers=rest_headers, auth=auth_provider)
except Exception as er:
warnings.warn(f"Unable to get server version: {er}, default to None")
logging.debug(f"Unable to get server version: {er}, server version defaults to None")
return None

if response.status_code == 200:
version_info = response.json().get("version", None)
if not version_info:
warnings.warn(f"Unable to parse response from server: {response}, default to None")
logging.debug(
f"Unable to parse response from server: {response}, server version defaults to None"
)
return version_info
else:
warnings.warn(f"Unexpected response from server: {response}, default to None")
logging.debug(
f"Unexpected response from server: {response}, server version defaults to None"
)
return None


Expand All @@ -40,13 +45,13 @@ def parse_version(version: str) -> Version:
) from er


def is_versions_compatible(client_version: Optional[str], server_version: Optional[str]) -> bool:
def is_compatible(client_version: Optional[str], server_version: Optional[str]) -> bool:
if not client_version:
warnings.warn(f"Unable to compare with client version {client_version}")
logging.debug(f"Unable to compare with client version {client_version}")
return False

if not server_version:
warnings.warn(f"Unable to compare with server version {server_version}")
logging.debug(f"Unable to compare with server version {server_version}")
return False

if client_version == server_version:
Expand All @@ -56,7 +61,7 @@ def is_versions_compatible(client_version: Optional[str], server_version: Option
parsed_server_version = parse_version(server_version)
parsed_client_version = parse_version(client_version)
except ValueError as er:
warnings.warn(f"Unable to compare versions: {er}")
logging.debug(f"Unable to compare versions: {er}")
return False

major_dif = abs(parsed_server_version.major - parsed_client_version.major)
Expand Down
8 changes: 6 additions & 2 deletions qdrant_client/qdrant_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from qdrant_client._pydantic_compat import construct
from qdrant_client.auth import BearerAuth
from qdrant_client.client_base import QdrantBase
from qdrant_client.common.version_check import is_versions_compatible, get_server_version
from qdrant_client.common.version_check import is_compatible, get_server_version
from qdrant_client.connection import get_async_channel, get_channel
from qdrant_client.conversions import common_types as types
from qdrant_client.conversions.common_types import get_args_subscribed
Expand Down Expand Up @@ -201,7 +201,11 @@ def __init__(
server_version = get_server_version(
self.rest_uri, self._rest_headers, self._rest_args.get("auth")
)
if not is_versions_compatible(client_version, server_version):
if not server_version:
warnings.warn(
f"Failed to obtain server version. Unable to check client-server compatibility. Set check_version=False to skip version check."
)
elif not is_compatible(client_version, server_version):
warnings.warn(
f"Qdrant client version {client_version} is incompatible with server version {server_version}. Major versions should match and minor version difference must not exceed 1. Set check_version=False to skip version check."
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from qdrant_client.common.version_check import is_versions_compatible, parse_version
from qdrant_client.common.version_check import is_compatible, parse_version


@pytest.mark.parametrize(
Expand Down Expand Up @@ -42,7 +42,7 @@
)
def test_check_versions(client_version, server_version, expected_result):
assert (
is_versions_compatible(client_version=client_version, server_version=server_version)
is_compatible(client_version=client_version, server_version=server_version)
is expected_result
)

Expand Down

0 comments on commit 628e09b

Please sign in to comment.