model_bakery icon indicating copy to clipboard operation
model_bakery copied to clipboard

`_bulk_create` without `_quantity` will be ignored

Open jedie opened this issue 2 years ago • 4 comments

e.g.: baker.make(MyModel, _bulk_create=True) will no use bulk create, because _quantity can't be None, so _bulk_create will be just ignored, see:

https://github.com/model-bakers/model_bakery/blob/38d2dd797832adcd2523048830d0843732acd9c4/model_bakery/baker.py#L126-L127

I think it's not very much to do, to support this case, isn't it? I can create a PR, if this is ok.

Versions

  • Model Bakery 1.17.0

jedie avatar Nov 02 '23 08:11 jedie

what's the expected behavior? raising exception mentioning that _quantity should be specified?

mattwang44 avatar Mar 11 '25 09:03 mattwang44

Hi @jedie,

Sorry it took so long to get back to this issue!

I'm trying to understand your use case better. When you call baker.make(MyModel, _bulk_create=True) without _quantity, what would be your expected behavior?

A few possibilities I can think of:

  1. Create a single object using bulk_create() (equivalent to _quantity=1, _bulk_create=True) - I presume that is what you expected?
  2. Raise an error/warning that _bulk_create requires passing _quantity

Could you help clarify what your use case is and what you'd expect to happen? This will help us align on the right solution.

If you're still interested in providing a PR for this, that would be very welcome! Otherwise, once we agree on the expected behavior, we can implement it.

Thanks for bringing this up!

amureki avatar Jul 25 '25 12:07 amureki

I am happy to get back to it and reopen; feel free to post a reply!

amureki avatar Aug 15 '25 07:08 amureki

Create a single object using bulk_create() (equivalent to _quantity=1, _bulk_create=True) - I presume that is what you expected?

Yes, this is it. Think it was about to skip signal handling on creation. But can't remember...

(I have no permission to reopen this issue ;)

jedie avatar Aug 15 '25 08:08 jedie