Skip to content

Commit

Permalink
Do not change config in place
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Aug 6, 2024
1 parent 4a65177 commit da578de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
21 changes: 15 additions & 6 deletions src/mass/adapters/outbound/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,21 @@ def build_pipeline( # noqa: PLR0913
pipeline.append(pipeline_match_filters_stage(filters=filters))

# turn the selected fields into a formatted pipeline $project
project: dict[str, int] = dict.fromkeys(
[
field.key if field.key == "id_" else f"content.{field.key}"
for field in selected_fields
],
1,

project: dict[str, int] | None = (
dict.fromkeys(
(
"id_",
*(
f"content.{field.key}"
for field in selected_fields
if field.key != "id_"
),
),
1,
)
if selected_fields
else None
)

# turn the sorting parameters into a formatted pipeline $sort
Expand Down
6 changes: 1 addition & 5 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, C901, D102
async def handle_query( # noqa: D102, PLR0913
self,
*,
class_name: str,
Expand Down Expand Up @@ -103,10 +103,6 @@ async def handle_query( # noqa: PLR0913, C901, 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 da578de

Please sign in to comment.