tortoise / tortoise/tortoise-orm
Bulk Create without returning objects
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
The main problem here is that bulk_create converts objects to a list before insertion which loads all the models at the same time. The only reason for this is to return the inserted objects after the query is done. However, those objects are not being updated (adding pk for example), i.e the mothod will return what you sent. I think we can enhance this and make bulk_create benefits from #1613 .
Describe the solution you'd like
There are several approaches for this:
- Do not return anything from
bulk_createor return the number of inserted rows. This maybe a breaking change. - Add a keyword argument called
return_objectsor something like that to control the behaviour. - Do not return anything when
batch_sizeis set.
If none of the above seems logical, I think at least we should mention what is going behind the scenes in the docs, so the user can handle chunking on his own. And maybe use tuple(objects) instead of list(objects).
Describe alternatives you've considered
The most natural alternative is to chunk data on your side and leave batch_size as None. But this makes batch_size useless.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the bulk_create implementation and the discussion in this issue, then inspect how batch_size currently affects insertion and returned objects. The issue presents several incompatible API options without selecting one, so done requires an agreed behavior that avoids unnecessary eager loading or clearly documents the existing behavior, with corresponding tests or documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100