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

make() with _bulk_create=True does not create M2M-entries that are specified using the reverse/related name. #385

Open
richardebeling opened this issue Jan 17, 2023 · 0 comments

Comments

@richardebeling
Copy link

When using baker.make with _bulk_create=True, it will silently ignore arguments that should be used to fill many-to-many fields if the arguments use the reverve/related name.

Follow up to #298, where the same issue was fixed when using the forward name of a m2m relationship.

To Reproduce
with

class House(models.Model):
     pass

class HouseDetail(models.Model):
    houses = models.ManyToManyField(House, blank=True)

this snippet fails at the assertion:

detail = baker.make(HouseDetail)
houses = baker.make(House, housedetail_set=[detail], _quantity=20, _bulk_create=True)
assert houses[0].housedetail_set.count() == 1

Expected behavior
For each house instance in houses, the housedetail_set should contain the detail, and thus have count() == 1. This also happens when _bulk_create=False is used.

Versions

  • Python: [3.10.6]
  • Django [4.1.6]
  • Model Bakery [1.9.0]
magdumsuraj07 added a commit to magdumsuraj07/model_bakery that referenced this issue Nov 14, 2023
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

No branches or pull requests

1 participant