Skip to content

Commit

Permalink
Make sure id_ is always selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Aug 5, 2024
1 parent ef00a98 commit c397125
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/mass/core/query_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def delete_resource(self, *, resource_id: str, class_name: str): # noqa:
except ResourceNotFoundError as err:
raise self.ResourceNotFoundError(resource_id=resource_id) from err

async def handle_query( # noqa: PLR0913, D102
async def handle_query( # noqa: PLR0913, C901, D102
self,
*,
class_name: str,
Expand All @@ -90,7 +90,7 @@ async def handle_query( # noqa: PLR0913, D102
sorting_parameters = []

# if id_ is not in sorting_parameters, add to end
if "id_" not in [param.field for param in sorting_parameters]:
if not any(param.field == "id_" for param in sorting_parameters):
sorting_parameters.append(
models.SortingParameter(field="id_", order=models.SortOrder.ASCENDING)
)
Expand All @@ -103,6 +103,10 @@ async def handle_query( # noqa: PLR0913, D102
except KeyError as err:
raise self.ClassNotConfiguredError(class_name=class_name) from err

# if id_ is not in selected_fields, add as first field
if selected_fields and not any(field.key == "id_" for field in selected_fields):
selected_fields.insert(0, models.FieldLabel(key="id_", name="ID"))

# run the aggregation. Results will have {facets, count, hits} format
aggregator = self._aggregator_collection.get_aggregator(class_name=class_name)
for attempt in range(2):
Expand Down

0 comments on commit c397125

Please sign in to comment.