Skip to content
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

[#65] Add _bulk_create parameter to make #134

Merged

Conversation

timjklein36
Copy link
Collaborator

  • This enables the use of bulk_create for the models that are
    created with _quantity supplied. This could offer performance
    advantages when creating large quantities of data.
  • It works by instead "preparing" the models and supplying them
    to the _base_manager.bulk_create.

Fixes #65

@timjklein36
Copy link
Collaborator Author

@berinhard @anapaulagomes I am not sure the root cause of the GitHub Action failures or whether there is anything I can do to fix them.

For what it's worth, the tests are passing on my local machine (even the PostgreSQL and Postgis tests).

@anapaulagomes
Copy link
Contributor

I'm looking into it @timjklein36.

@berinhard
Copy link
Member

@anapaulagomes it seems to be an issue with Ubuntu's repositories:

Err:27 http://security.ubuntu.com/ubuntu bionic-updates/main amd64 libpoppler73 amd64 0.62.0-2ubuntu2.10
  404  Not Found [IP: 52.154.174.208 80]

@anapaulagomes
Copy link
Contributor

Yeah, I saw this @berinhard. I tried to fix it with a suggestion from the GA community but it didn't work (#135). I'll continue tomorrow.

@amureki
Copy link
Collaborator

amureki commented Nov 30, 2020

@timjklein36 could you, please, rebase your change? @anapaulagomes fixed the issue, so it should work now!

- This enables the use of `bulk_create` for the models that are
  created with `_quantity` supplied. This could offer performance
  advantages when creating large quantities of data.
- It works by instead "preparing" the models and supplying them
  to the `_base_manager.bulk_create`.
- This tests to make sure `_bulk_create` works with models that
  have custom Managers.
- This adds an assertion that without `_bulk_create=True` there
  will be the number of queries to the DB equal to the value of
  `_quantity`.
Copy link
Contributor

@anapaulagomes anapaulagomes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me! My only note is about the use of _refresh_after_create.

Thank you for another valuable contribution, @timjklein36.

model_bakery/baker.py Outdated Show resolved Hide resolved
tests/test_baker.py Show resolved Hide resolved
- This is not needed when using _bulk_create since prepare does
  not save the models directly
- Kwarg already has a default value and `None` is not needed as
  a valid value, so no need for the `Optional` type.
@timjklein36
Copy link
Collaborator Author

@anapaulagomes @berinhard @amureki Ready for your re-review at your earliest convenience. Thanks!

Copy link
Member

@berinhard berinhard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great work! Thanks @timjklein36

tests/test_baker.py Show resolved Hide resolved
@anapaulagomes anapaulagomes self-requested a review December 4, 2020 20:52
Copy link
Contributor

@anapaulagomes anapaulagomes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 🏆

@anapaulagomes anapaulagomes merged commit 9353ab8 into model-bakers:main Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use bulk_create when supplying _quantity parameter to baker.make
4 participants