Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto capitalize target collection in by_ref_multi_target #1471

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
8 changes: 7 additions & 1 deletion test/collection/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -86,3 +86,9 @@ 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"
4 changes: 3 additions & 1 deletion weaviate/collections/classes/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -537,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
Expand Down
Loading