Skip to content

Commit

Permalink
fix: Fix save_many() when there are no models to insert (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artucuno authored Nov 23, 2023
1 parent 2dc5149 commit 6b0912d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pydantic_mongo/abstract_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ def save_many(self, models: Iterable[T]):
models_to_update.append(model)
else:
models_to_insert.append(model)
if len(models_to_insert) > 0:
result = self.get_collection().insert_many(
(self.to_document(model) for model in models_to_insert)
)

result = self.get_collection().insert_many(
(self.to_document(model) for model in models_to_insert)
)

for idx, inserted_id in enumerate(result.inserted_ids):
models_to_insert[idx].id = inserted_id
for idx, inserted_id in enumerate(result.inserted_ids):
models_to_insert[idx].id = inserted_id

if len(models_to_update) == 0:
return
Expand Down

0 comments on commit 6b0912d

Please sign in to comment.