Conversation
amureki
left a comment
There was a problem hiding this comment.
I've got a couple of comments on this PR. And I left a comment on the issue itself, as I am curious more about the context.
Many thanks for the contribution, though!
Since the bulk create is being done within a transaction block to prevent objects from being created if invalid error, the number of expected queries increases by 2 since the transaction runs the statement to register the rollback checkpoint and the commit one.
|
Thanks for you review @amureki. I addressed your comments with my new commits 👍 |
amureki
left a comment
There was a problem hiding this comment.
Excellent fixes, thanks for moving the check and adding the test!
I left some last nitpicky notes, but in general it is good to go!
There was a problem hiding this comment.
I believe, this file should not be commited, as it belongs to a local dev setup.
I think you recently added it to .gitignore, so this is solved on main branch already.
| - New flag `_full_clean` to run model validation at created instances (`False` by default) | ||
|
|
||
| ### Changed | ||
| - Bulk creation of models instances is now done within a Django transaction block |
There was a problem hiding this comment.
| - Bulk creation of models instances is now done within a Django transaction block | |
| - Bulk creation now uses transaction blocks to ensure atomic rollback when `_full_clean=True` validation fails |
| customer = baker.make('shop.Customer', _fill_optional=True) | ||
| ``` | ||
|
|
||
| By default, Model Bakery won't run validations on custom fields definitions. To enforce the returned |
There was a problem hiding this comment.
Thanks for updating the doc!
Shall we also add a small note on atomicity?
When using
_full_clean=Truewith_bulk_create=True, all objects are created within a transaction and will be rolled back if any validation errors occur.
Closes #523
This PR introuces the
_full_cleanflag to every API to create/prepare objects. By default the flag is set toFalseto not introduce backwards incompatibilities.