Skip to content

Commit

Permalink
remove return objects list in bulk_create (#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdeldjalil-H committed May 14, 2024
1 parent 7cb7e72 commit ca50d99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Changed
- Change `utils.chunk` from function to return iterables lazily.
- Removed lower bound of id keys in generated pydantic models. (#1602)

Breaking Changes
^^^^^^^^^^^^^^^^
- `bulk_create` now does not return anything. (#1614)

0.20
====
Expand Down
10 changes: 4 additions & 6 deletions tortoise/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,7 @@ def bulk_create(
) -> "BulkCreateQuery[MODEL]":
"""
This method inserts the provided list of objects into the database in an efficient manner
(generally only 1 query, no matter how many objects there are),
and returns created objects as a list, in the same order as provided
(generally only 1 query, no matter how many objects there are).
:param on_conflict: On conflict index name
:param update_fields: Update fields when conflicts
Expand Down Expand Up @@ -1861,7 +1860,7 @@ def __init__(
on_conflict: Optional[Iterable[str]] = None,
):
super().__init__(model)
self.objects = list(objects)
self.objects = objects
self.ignore_conflicts = ignore_conflicts
self.batch_size = batch_size
self._db = db
Expand Down Expand Up @@ -1902,7 +1901,7 @@ def _make_query(self) -> None:
)
self.insert_query = self.insert_query.do_update(update_field) # type:ignore

async def _execute(self) -> List[MODEL]:
async def _execute(self) -> None:
for instance_chunk in chunk(self.objects, self.batch_size):
values_lists_all = []
values_lists = []
Expand All @@ -1929,9 +1928,8 @@ async def _execute(self) -> List[MODEL]:
await self._db.execute_many(str(self.insert_query_all), values_lists_all)
if values_lists:
await self._db.execute_many(str(self.insert_query), values_lists)
return self.objects

def __await__(self) -> Generator[Any, None, List[MODEL]]:
def __await__(self) -> Generator[Any, None, None]:
if self._db is None:
self._db = self._choose_db(True) # type: ignore
self._make_query()
Expand Down

0 comments on commit ca50d99

Please sign in to comment.