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

GenericForeignKey, Django 5.1 getting incorrect object_id and content_type #488

Closed
james-certn opened this issue Aug 9, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@james-certn
Copy link

james-certn commented Aug 9, 2024

Describe the issue
#483 was a step to improved GFK support in bakery - thank you!

I'm seeing an issue with GFK support in current model-bakery, where a random object_id and content_type is associated with a random other object rather than the one specified by content_object in the baker.make(...) call.

To Reproduce

    new_obj = baker.make(
        MyModelWithGFK,
        content_object=my_object,
    )

    obj_from_db = MyModelWithGFK.objects.get(pk=new_obj.pk)

obj_from_db.object_id and new_obj.object_id are different; same with content_type.

Expected behavior
From the example above:

obj_from_db.object_id and new_obj.object_id should be identical; same with content_type.

Our tests appear to run correctly (with this result) in Django 4.2 with model-bakery 1.18.2.

Versions

  • Python: 3.11.9
  • Django: 5.1
  • Model Bakery: 1.19.1
@dwoldenberg1
Copy link

+1 experiencing issues of a similar nature as well

@amureki amureki added the bug Something isn't working label Aug 10, 2024
@amureki
Copy link
Collaborator

amureki commented Aug 10, 2024

Hey there,

thank you for the bug report!
This confirms that we should solve the problem a bit differently, and I'd need to think about it.
The issue here is that the GFK fields are treated separately and do not know about the state and the context of each other.

So we'd need to find a way to either treat them together, or to pass the context to the generators.
I'd be happy to hear the ideas or suggestions and will try to get to it soon.

@mochams
Copy link

mochams commented Aug 12, 2024

+1 experiencing issues of a similar nature as well

Failing versions

Python: 3.11.7
Django: 5.0.8
Model Bakery: 1.18.3
Python: 3.11.7
Django: 5.0.8
Model Bakery: 1.19.1

Working versions

Python: 3.11.7
Django: 5.0.8
Model Bakery: 1.18.2

@amureki
Copy link
Collaborator

amureki commented Aug 16, 2024

Greetings everyone!

Thank you for the reports!
I released 1.19.2 with patch handling this bug:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants