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

This is related to #487, which is now closed. #498

Closed
paulredman- opened this issue Aug 22, 2024 · 3 comments
Closed

This is related to #487, which is now closed. #498

paulredman- opened this issue Aug 22, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@paulredman-
Copy link

Describe the issue
When setting a GenericForeignKey to None, the component parts are created.

To Reproduce

Definition for comms.Message

relates_to_id = models.PositiveIntegerField(null=True, blank=True)
relates_to_type = models.ForeignKey(ContentType, null=True, blank=True, on_delete=models.PROTECT)
relates_to = GenericForeignKey('relates_to_type', 'relates_to_id')

# Failing test code
    from_message = baker.make(
        'comms.Message', _fill_optional=True, from_user=lawyer.user, to_user=client.user, relates_to=None
    )

    self.assertIsNone(from_message.relates_to)

    # These two both fail with model_bakery==1.19.4
    self.assertIsNone(from_message.relates_to_type_id)
    self.assertIsNone(from_message.relates_to_id)

Expected behavior
If relates_to is set to None, then relates_to_id and relates_to_type_id are both set to None for a GenericForeignKey

Versions
1.19.4

  • Python: [e.g. 3.10]
  • Django [e.g. 4.1]
  • Model Bakery [e.g. 1.6.0]

Rust,
I'd appreciate your thoughts on this. We could set relates_to_id and relates_to_type_id explicitly to None in our code, but I'm not sure this is the right answer. Please let me know if you need any more information on this to help diagnose the problem.

@amureki amureki added the bug Something isn't working label Aug 23, 2024
@amureki amureki self-assigned this Aug 23, 2024
@amureki
Copy link
Collaborator

amureki commented Aug 23, 2024

Hey Paul!

I agree that this should be solved by the library and not by manually updating all the places using GFKs.
I am adjusting the logic in #499 to handle this behaviour.

@paulredman-
Copy link
Author

paulredman- commented Aug 23, 2024 via email

@paulredman-
Copy link
Author

paulredman- commented Aug 29, 2024 via email

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

2 participants