Skip to content

Commit

Permalink
🚑 Fix pipeline set stage with correct index and set empty array for i…
Browse files Browse the repository at this point in the history
…ndex null
  • Loading branch information
mauro-andre committed Jan 16, 2025
1 parent 845a22a commit ca3a13b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pyodmongo/services/aggregate_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def group_set_replace_root(
f"_document.{path_str}": {
"$cond": {
"if": {"$eq": [f"$_document.{array_index}", None]},
"then": None,
"then": [],
# "then": None,
"else": f"${field}",
}
}
Expand Down
5 changes: 3 additions & 2 deletions pyodmongo/services/reference_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ def resolve_reference_pipeline(
id_ = [
f"${e}" for e in unwind_index_list[: len(unwind_index_list) - index - 1]
]
index_to_unset.append(unwind_index_list[-(index + 1)])
current_index = unwind_index_list[-(index + 1)]
index_to_unset.append(current_index)
to_sort = {key: 1 for key in unwind_index_list[1:]}
pipeline += group_set_replace_root(
to_sort=to_sort,
id_=id_,
array_index=unwind_index_list[-1],
array_index=current_index,
field=path_str.split(".")[-1],
path_str=path_str,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class B(MainBaseModel):

class C(DbModel):
name: str = "name_1"
b_list: list[B] | None = None
b_list: list[B] = []
_collection: ClassVar = "c"

obj_c = C()
Expand Down

0 comments on commit ca3a13b

Please sign in to comment.