-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add support for debug get object endpoint:
- Loading branch information
Showing
10 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from integration.conftest import ClientFactory, CollectionFactory | ||
|
||
from weaviate.classes.config import DataType, Property | ||
from weaviate.classes.debug import DebugRESTObject | ||
|
||
|
||
def test_get_object_single_node( | ||
client_factory: ClientFactory, collection_factory: CollectionFactory | ||
) -> None: | ||
client = client_factory() | ||
collection = collection_factory(properties=[Property(name="name", data_type=DataType.TEXT)]) | ||
|
||
uuid = collection.data.insert({"name": "John Doe"}) | ||
|
||
debug_obj = client.debug.get_object_over_rest(collection.name, uuid) | ||
assert debug_obj is not None | ||
assert isinstance(debug_obj, DebugRESTObject) | ||
assert str(debug_obj.uuid) == str(uuid) | ||
|
||
non_existant_uuid = "00000000-0000-0000-0000-000000000000" | ||
debug_obj = client.debug.get_object_over_rest(collection.name, non_existant_uuid) | ||
assert debug_obj is None | ||
|
||
|
||
def test_get_object_multi_node( | ||
client_factory: ClientFactory, collection_factory: CollectionFactory | ||
) -> None: | ||
client = client_factory(ports=(8087, 50058)) | ||
collection = collection_factory( | ||
ports=(8087, 50058), properties=[Property(name="name", data_type=DataType.TEXT)] | ||
) | ||
|
||
uuid = collection.data.insert({"name": "John Doe"}) | ||
|
||
for node_name in ["node1", "node2", "node3"]: | ||
debug_obj = client.debug.get_object_over_rest(collection.name, uuid, node_name=node_name) | ||
assert debug_obj is not None | ||
assert str(debug_obj.uuid) == str(uuid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from weaviate.debug.types import DebugRESTObject | ||
|
||
__all__ = [ | ||
"DebugRESTObject", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from .debug import _DebugAsync | ||
from .sync import _Debug | ||
|
||
__all__ = [ | ||
"_Debug", | ||
"_DebugAsync", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from typing import Dict, Optional | ||
|
||
from weaviate.classes.config import ConsistencyLevel | ||
from weaviate.connect import ConnectionV4 | ||
from weaviate.connect.v4 import _ExpectedStatusCodes | ||
from weaviate.debug.types import DebugRESTObject | ||
from weaviate.types import UUID | ||
|
||
|
||
class _DebugBase: | ||
def __init__( | ||
self, | ||
connection: ConnectionV4, | ||
) -> None: | ||
self._connection = connection | ||
|
||
|
||
class _DebugAsync(_DebugBase): | ||
async def get_object_over_rest( | ||
self, | ||
collection: str, | ||
uuid: UUID, | ||
*, | ||
consistency_level: Optional[ConsistencyLevel] = None, | ||
node_name: Optional[str] = None, | ||
tenant: Optional[str] = None, | ||
) -> Optional[DebugRESTObject]: | ||
"""Use the REST API endpoint /objects/{className}/{id} to retrieve an object directly from the database without search. | ||
The key difference between `debug.get_object_over_rest` and `query.fetch_object_by_id` is the underlying protocol. | ||
This method uses REST while that method uses gRPC. | ||
""" | ||
path = f"/objects/{collection}/{str(uuid)}" | ||
|
||
params: Dict[str, str] = {} | ||
if consistency_level is not None: | ||
params["consistency"] = consistency_level.value | ||
if node_name is not None: | ||
params["node_name"] = node_name | ||
if tenant is not None: | ||
params["tenant"] = tenant | ||
|
||
res = await self._connection.get( | ||
path=path, | ||
params=params, | ||
error_msg="Object was not retrieved", | ||
status_codes=_ExpectedStatusCodes(ok_in=[200, 404], error="get object"), | ||
) | ||
if res.status_code == 404: | ||
return None | ||
return DebugRESTObject(**res.json()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from weaviate import syncify | ||
from weaviate.debug.debug import _DebugAsync | ||
|
||
|
||
@syncify.convert | ||
class _Debug(_DebugAsync): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from typing import Optional | ||
|
||
from weaviate.classes.config import ConsistencyLevel | ||
from weaviate.debug.debug import _DebugBase | ||
from weaviate.debug.types import DebugRESTObject | ||
from weaviate.types import UUID | ||
|
||
class _Debug(_DebugBase): | ||
def get_object_over_rest( | ||
self, | ||
collection: str, | ||
uuid: UUID, | ||
*, | ||
consistency_level: Optional[ConsistencyLevel] = None, | ||
node_name: Optional[str] = None, | ||
tenant: Optional[str] = None, | ||
) -> Optional[DebugRESTObject]: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from datetime import datetime | ||
from typing import Any, Dict, Optional | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from weaviate.types import uuid_package | ||
|
||
|
||
class DebugRESTObject(BaseModel): | ||
collection: str = Field(..., alias="class") | ||
creation_time: datetime = Field(..., alias="creationTimeUnix") | ||
last_update_time: datetime = Field(..., alias="lastUpdateTimeUnix") | ||
properties: Dict[str, Any] = Field(...) | ||
tenant: Optional[str] = Field(None) | ||
uuid: uuid_package.UUID = Field(..., alias="id") | ||
vector: Optional[list[float]] = Field(None) | ||
vectors: Optional[Dict[str, list[float]]] = Field(None) |