Skip to content

Commit

Permalink
Merge pull request #379 from weaviate/fix-additional-properties-bug
Browse files Browse the repository at this point in the history
Fix additional properties bug
  • Loading branch information
dirkkul authored Jul 11, 2023
2 parents 32e6b2a + d328bcc commit f5a6864
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions test/gql/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,40 @@
@pytest.mark.parametrize(
"props,expected",
[
(AdditionalProperties(uuid=True), "_additional{id}"),
(AdditionalProperties(uuid=True), " _additional{id} "),
(
AdditionalProperties(uuid=True, vector=True, explainScore=True),
"_additional{id vector explainScore}",
" _additional{id vector explainScore} ",
),
(
AdditionalProperties(uuid=False, vector=True, explainScore=True, score=True),
"_additional{vector score explainScore}",
" _additional{vector score explainScore} ",
),
],
)
def test_additional_props(props: AdditionalProperties, expected: str):
assert str(props) == expected


@pytest.mark.parametrize(
"additional_props,expected",
[
(AdditionalProperties(uuid=True), " _additional{id} "),
],
)
def test_getbuilder_with_additional_props(additional_props: AdditionalProperties, expected: str):
query = (
GetBuilder("TestClass", "name", mock_connection_v117)
.with_additional(additional_props)
.build()
)
expected_query = "{Get{TestClass{name" + expected + "}}}"
assert (
"name_" not in expected_query
) # Check that the prop name is not being concatnated to _additional
assert query == expected_query


@pytest.mark.parametrize(
"query,properties,expected",
[
Expand Down
2 changes: 1 addition & 1 deletion weaviate/gql/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __str__(self) -> str:
name = "id"
additional_props.append(name)
if len(additional_props) > 0:
return "_additional{" + " ".join(additional_props) + "}"
return " _additional{" + " ".join(additional_props) + "} "
else:
return ""

Expand Down

0 comments on commit f5a6864

Please sign in to comment.