Skip to content
Open
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
30 changes: 29 additions & 1 deletion test/collection/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import pytest

from weaviate.collections.batch.grpc_batch import _validate_props
from weaviate.collections.classes.batch import MAX_STORED_RESULTS, BatchObjectReturn
from weaviate.collections.classes.batch import (
MAX_STORED_RESULTS,
BatchObject,
BatchObjectReturn,
ErrorObject,
)
from weaviate.exceptions import WeaviateInsertInvalidPropertyError


Expand Down Expand Up @@ -53,3 +58,26 @@ def test_validate_props_raises_for_top_level_vector() -> None:
def test_validate_props_raises_for_nested_vector() -> None:
with pytest.raises(WeaviateInsertInvalidPropertyError):
_validate_props({"vector": [0.1, 0.2]}, nested=True)


def test_error_object_original_uuid_is_set_from_batch_object() -> None:
"""ErrorObject should preserve the original_uuid from the BatchObject that failed."""
obj_uuid = uuid.uuid4()
obj = BatchObject(collection="TestCollection", uuid=obj_uuid, index=0)
error = ErrorObject(message="some error", object_=obj, original_uuid=obj.uuid)
assert str(error.original_uuid) == str(obj_uuid)


def test_error_object_original_uuid_not_none_when_object_has_uuid() -> None:
"""When building ErrorObjects in the exception path, original_uuid must not be None."""
objs = [
BatchObject(collection="TestCollection", uuid=uuid.uuid4(), index=i) for i in range(3)
]
# Simulate what base.py does in the exception handler after the fix
errors_obj = {
idx: ErrorObject(message="connection error", object_=obj, original_uuid=obj.uuid)
for idx, obj in enumerate(objs)
}
for idx, obj in enumerate(objs):
assert errors_obj[idx].original_uuid is not None
assert errors_obj[idx].original_uuid == obj.uuid
2 changes: 1 addition & 1 deletion weaviate/collections/batch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def __send_batch(
)
except Exception as e:
errors_obj = {
idx: ErrorObject(message=repr(e), object_=obj) for idx, obj in enumerate(objs)
idx: ErrorObject(message=repr(e), object_=obj, original_uuid=obj.uuid) for idx, obj in enumerate(objs)
}
logger.error(
{
Expand Down