From 120a62de7a5a02975181b178fb61022498bfd2c6 Mon Sep 17 00:00:00 2001 From: melsonic Date: Tue, 10 Dec 2024 23:52:00 +0530 Subject: [PATCH 1/6] auto capitalize target collection in by_ref_multi_target --- weaviate/collections/classes/filters.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/weaviate/collections/classes/filters.py b/weaviate/collections/classes/filters.py index 2c799c005..2b74fc1c8 100644 --- a/weaviate/collections/classes/filters.py +++ b/weaviate/collections/classes/filters.py @@ -9,7 +9,7 @@ from weaviate.collections.classes.types import _WeaviateInput from weaviate.types import UUID from weaviate.proto.v1 import base_pb2 -from weaviate.util import get_valid_uuid +from weaviate.util import get_valid_uuid, _capitalize_first_letter from weaviate.exceptions import WeaviateInvalidInputError @@ -489,6 +489,7 @@ def by_ref(self, link_on: str) -> "_FilterByRef": def by_ref_multi_target(self, reference: str, target_collection: str) -> "_FilterByRef": """Filter on the given multi-target reference.""" + target_collection = _capitalize_first_letter(target_collection) self.__last_target.target = _MultiTargetRef( link_on=reference, target_collection=target_collection ) From 29e191afe117075bd3001c5369b81671d785eaf2 Mon Sep 17 00:00:00 2001 From: melsonic Date: Fri, 13 Dec 2024 23:37:51 +0530 Subject: [PATCH 2/6] added integration test --- integration/test_collection_filter.py | 6 ++++++ weaviate/collections/classes/filters.py | 1 + 2 files changed, 7 insertions(+) diff --git a/integration/test_collection_filter.py b/integration/test_collection_filter.py index 01fc7fe9f..5d8042a4a 100644 --- a/integration/test_collection_filter.py +++ b/integration/test_collection_filter.py @@ -825,3 +825,9 @@ def test_filter_by_ref_and_multi_ref(collection_factory: CollectionFactory) -> N ).objects assert objects[0].uuid == uuid23 + + +def test_auto_capitalize_by_ref_multi_target() -> None: + result = Filter.by_ref_multi_target(link_on="ref1", target_collection="test") + target_collection_stored = result._FilterByRef__target.target_collection + assert target_collection_stored == "Test" diff --git a/weaviate/collections/classes/filters.py b/weaviate/collections/classes/filters.py index 2b74fc1c8..03cc83b36 100644 --- a/weaviate/collections/classes/filters.py +++ b/weaviate/collections/classes/filters.py @@ -538,6 +538,7 @@ def by_ref(link_on: str) -> _FilterByRef: @staticmethod def by_ref_multi_target(link_on: str, target_collection: str) -> _FilterByRef: """Define a filter based on a reference to be used when querying and deleting from a collection.""" + target_collection = _capitalize_first_letter(target_collection) return _FilterByRef(_MultiTargetRef(link_on=link_on, target_collection=target_collection)) @staticmethod From faef00ef8e1159f64b136b437e8f29b3b87807d7 Mon Sep 17 00:00:00 2001 From: melsonic Date: Fri, 13 Dec 2024 23:40:09 +0530 Subject: [PATCH 3/6] updated test name --- integration/test_collection_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/test_collection_filter.py b/integration/test_collection_filter.py index 5d8042a4a..6c649a5a8 100644 --- a/integration/test_collection_filter.py +++ b/integration/test_collection_filter.py @@ -827,7 +827,7 @@ def test_filter_by_ref_and_multi_ref(collection_factory: CollectionFactory) -> N assert objects[0].uuid == uuid23 -def test_auto_capitalize_by_ref_multi_target() -> None: +def test_auto_capitalize_first_letter_by_ref_multi_target() -> None: result = Filter.by_ref_multi_target(link_on="ref1", target_collection="test") target_collection_stored = result._FilterByRef__target.target_collection assert target_collection_stored == "Test" From 778b99584c379bb25621f26e6c283c702d1df8cc Mon Sep 17 00:00:00 2001 From: melsonic Date: Tue, 17 Dec 2024 19:56:25 +0530 Subject: [PATCH 4/6] moved test to test/collection/test_filter.py --- integration/test_collection_filter.py | 5 ----- test/collection/test_filter.py | 7 ++++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/integration/test_collection_filter.py b/integration/test_collection_filter.py index 6c649a5a8..5514df99f 100644 --- a/integration/test_collection_filter.py +++ b/integration/test_collection_filter.py @@ -826,8 +826,3 @@ def test_filter_by_ref_and_multi_ref(collection_factory: CollectionFactory) -> N assert objects[0].uuid == uuid23 - -def test_auto_capitalize_first_letter_by_ref_multi_target() -> None: - result = Filter.by_ref_multi_target(link_on="ref1", target_collection="test") - target_collection_stored = result._FilterByRef__target.target_collection - assert target_collection_stored == "Test" diff --git a/test/collection/test_filter.py b/test/collection/test_filter.py index ff120e964..d5ece5904 100644 --- a/test/collection/test_filter.py +++ b/test/collection/test_filter.py @@ -4,7 +4,7 @@ import weaviate import weaviate.classes as wvc -from weaviate.collections.classes.filters import _FilterAnd, _FilterOr +from weaviate.collections.classes.filters import Filter, _FilterAnd, _FilterOr def test_empty_input_contains_any() -> None: @@ -86,3 +86,8 @@ def test_filter_bitwise_or_assignment() -> None: assert isinstance(or_direct.filters[0], _FilterOr) assert f4.filters[0].filters == or_direct.filters[0].filters assert f4.filters[1] == f3 + +def test_auto_capitalize_first_letter_by_ref_multi_target() -> None: + result = Filter.by_ref_multi_target(link_on="ref1", target_collection="test") + target_collection_stored = result._FilterByRef__target.target_collection + assert target_collection_stored == "Test" From a4290f6d3842c502d42fee221011d312cb173117 Mon Sep 17 00:00:00 2001 From: melsonic Date: Tue, 17 Dec 2024 19:57:36 +0530 Subject: [PATCH 5/6] clean up --- integration/test_collection_filter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/integration/test_collection_filter.py b/integration/test_collection_filter.py index 5514df99f..01fc7fe9f 100644 --- a/integration/test_collection_filter.py +++ b/integration/test_collection_filter.py @@ -825,4 +825,3 @@ def test_filter_by_ref_and_multi_ref(collection_factory: CollectionFactory) -> N ).objects assert objects[0].uuid == uuid23 - From 6bbcd2e3a931bce53f158c668d11bda169a80ce1 Mon Sep 17 00:00:00 2001 From: melsonic Date: Tue, 17 Dec 2024 20:25:36 +0530 Subject: [PATCH 6/6] formatter changes --- test/collection/test_filter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/collection/test_filter.py b/test/collection/test_filter.py index d5ece5904..c9bdd1c21 100644 --- a/test/collection/test_filter.py +++ b/test/collection/test_filter.py @@ -87,6 +87,7 @@ def test_filter_bitwise_or_assignment() -> None: assert f4.filters[0].filters == or_direct.filters[0].filters assert f4.filters[1] == f3 + def test_auto_capitalize_first_letter_by_ref_multi_target() -> None: result = Filter.by_ref_multi_target(link_on="ref1", target_collection="test") target_collection_stored = result._FilterByRef__target.target_collection