-
-
Notifications
You must be signed in to change notification settings - Fork 100
Issue 523 #547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
amureki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.