From c107fb3f9f1fdc37fe78588dc5da9e43682d9762 Mon Sep 17 00:00:00 2001 From: Hossam Hagag <90828745+hh-space-invader@users.noreply.github.com> Date: Fri, 13 Sep 2024 18:19:55 +0300 Subject: [PATCH] Tsk 757 add support for tuple in payload (#763) * Add support for tuple in payload for grpc * chore: delete health_check_pb2_grpc.py * chore: Modify payload test case to test tuple datatype * chore: Removed test case for tuple We cannot test tuple as the return value is listvalue, so i only kept the list * chore: Remove excess prints in info endpoint * chore: Added tuple in random payload generator * feat: convert the tuple payload of local mode to list for congruence --- qdrant_client/async_qdrant_remote.py | 1 - qdrant_client/conversions/conversion.py | 2 +- qdrant_client/grpc/health_check_pb2_grpc.py | 66 --------------------- qdrant_client/local/local_collection.py | 3 +- qdrant_client/qdrant_remote.py | 1 - tests/fixtures/payload.py | 1 + 6 files changed, 3 insertions(+), 71 deletions(-) delete mode 100644 qdrant_client/grpc/health_check_pb2_grpc.py diff --git a/qdrant_client/async_qdrant_remote.py b/qdrant_client/async_qdrant_remote.py index 8a13d8cf6..9befcd697 100644 --- a/qdrant_client/async_qdrant_remote.py +++ b/qdrant_client/async_qdrant_remote.py @@ -2831,6 +2831,5 @@ async def info(self) -> types.VersionInfo: version_info = self.grpc_root.HealthCheck(grpc.HealthCheckRequest()) return GrpcToRest.convert_health_check_reply(version_info) version_info = await self.rest.service_api.root() - print(version_info) assert version_info is not None, "Healthcheck returned None" return version_info diff --git a/qdrant_client/conversions/conversion.py b/qdrant_client/conversions/conversion.py index 45d570ad0..8de442e01 100644 --- a/qdrant_client/conversions/conversion.py +++ b/qdrant_client/conversions/conversion.py @@ -43,7 +43,7 @@ def json_to_value(payload: Any) -> Value: return Value(double_value=payload) if isinstance(payload, str): return Value(string_value=payload) - if isinstance(payload, list): + if isinstance(payload, (list, tuple)): return Value(list_value=ListValue(values=[json_to_value(v) for v in payload])) if isinstance(payload, dict): return Value( diff --git a/qdrant_client/grpc/health_check_pb2_grpc.py b/qdrant_client/grpc/health_check_pb2_grpc.py deleted file mode 100644 index 2435377a3..000000000 --- a/qdrant_client/grpc/health_check_pb2_grpc.py +++ /dev/null @@ -1,66 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -"""Client and server classes corresponding to protobuf-defined services.""" -import grpc - -from . import health_check_pb2 as health__check__pb2 - - -class HealthStub(object): - """Missing associated documentation comment in .proto file.""" - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.Check = channel.unary_unary( - '/grpc.health.v1.Health/Check', - request_serializer=health__check__pb2.HealthCheckRequest.SerializeToString, - response_deserializer=health__check__pb2.HealthCheckResponse.FromString, - ) - - -class HealthServicer(object): - """Missing associated documentation comment in .proto file.""" - - def Check(self, request, context): - """Missing associated documentation comment in .proto file.""" - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - -def add_HealthServicer_to_server(servicer, server): - rpc_method_handlers = { - 'Check': grpc.unary_unary_rpc_method_handler( - servicer.Check, - request_deserializer=health__check__pb2.HealthCheckRequest.FromString, - response_serializer=health__check__pb2.HealthCheckResponse.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'grpc.health.v1.Health', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) - - - # This class is part of an EXPERIMENTAL API. -class Health(object): - """Missing associated documentation comment in .proto file.""" - - @staticmethod - def Check(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/grpc.health.v1.Health/Check', - health__check__pb2.HealthCheckRequest.SerializeToString, - health__check__pb2.HealthCheckResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/qdrant_client/local/local_collection.py b/qdrant_client/local/local_collection.py index 87c1e2ccf..8d47c122f 100644 --- a/qdrant_client/local/local_collection.py +++ b/qdrant_client/local/local_collection.py @@ -80,8 +80,7 @@ def to_jsonable_python(x: Any) -> Any: try: - json.dumps(x, allow_nan=True) - return x + return json.loads(json.dumps(x, allow_nan=True)) except Exception: return json.loads(json.dumps(x, allow_nan=True, default=_to_jsonable_python)) diff --git a/qdrant_client/qdrant_remote.py b/qdrant_client/qdrant_remote.py index d2f15e48a..243a3fe83 100644 --- a/qdrant_client/qdrant_remote.py +++ b/qdrant_client/qdrant_remote.py @@ -3204,6 +3204,5 @@ def info(self) -> types.VersionInfo: version_info = self.grpc_root.HealthCheck(grpc.HealthCheckRequest()) return GrpcToRest.convert_health_check_reply(version_info) version_info = self.rest.service_api.root() - print(version_info) assert version_info is not None, "Healthcheck returned None" return version_info diff --git a/tests/fixtures/payload.py b/tests/fixtures/payload.py index ececfa213..09e96c938 100644 --- a/tests/fixtures/payload.py +++ b/tests/fixtures/payload.py @@ -217,6 +217,7 @@ def one_random_payload_please(idx: int) -> Dict[str, Any]: ], "two_words": [random_real_word(), random_real_word()], "city": random_city(), + "rand_tuple": tuple(random.randint(0, 100) for _ in range(random.randint(1, 5))), } if random.random() < 0.5: