Skip to content

Commit

Permalink
fix(LAB-3006): disable unicity check when id field not retrieved (#1746)
Browse files Browse the repository at this point in the history
Co-authored-by: Josselin BUILS <josselin.buils@kili-technology.com>
  • Loading branch information
josselinbuils and Josselin BUILS authored Jul 18, 2024
1 parent 0be43ae commit c66d61b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/kili/adapters/kili_api_gateway/asset/operations_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ def list_assets(
query = get_assets_query(fragment)
where = asset_where_mapper(filters)
assets_gen = PaginatedGraphQLQuery(self.graphql_client).execute_query_from_paginated_call(
query, where, options, "Retrieving assets", GQL_COUNT_ASSETS, "id"
query,
where,
options,
"Retrieving assets",
GQL_COUNT_ASSETS,
"id" if "id" in fields else None,
)
assets_gen = (
load_asset_json_fields(asset, fields, self.http_client) for asset in assets_gen
Expand Down
8 changes: 8 additions & 0 deletions src/kili/adapters/kili_api_gateway/helpers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def execute_query_from_paginated_call(
yield from elements
pbar.update(len(elements))
else:
check_unicity_field_presence(unicity_field, elements[0])

for element in elements:
unicity_value = element[unicity_field]

Expand Down Expand Up @@ -147,6 +149,12 @@ def get_number_of_elements_to_query(
return min(nb_elements_queried, first)


def check_unicity_field_presence(field: str, object: dict):
"""Check the presence of unicity field in queried elements."""
if field not in object:
raise ValueError(f"Unicity field {field} not found in queried elements")


@typechecked
def fragment_builder(
fields: ListOrTuple[str], static_fragments: Union[Dict[str, str], None] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,19 @@ def test_should_not_use_count_query_when_unicity_check_is_enabled(
),
]
)


def test_should_raise_an_exception_when_unicity_value_cannot_be_retrieved(
graphql_client: GraphQLClient,
):
# Given
options = QueryOptions(disable_tqdm=False, skip=0, first=None)

# When
gen = PaginatedGraphQLQuery(graphql_client).execute_query_from_paginated_call(
QUERY, WHERE, options, "", COUNT_QUERY, "cat"
)

# Then
with pytest.raises(ValueError):
list(gen)

0 comments on commit c66d61b

Please sign in to comment.