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

Fix #488 -- Align GFK and content type fields #494

Merged
merged 1 commit into from
Aug 16, 2024
Merged

Conversation

amureki
Copy link
Collaborator

@amureki amureki commented Aug 16, 2024

Describe the change
Replace a hacky workaround from 0b4cfa7#diff-7aca726c4b3af089805b51a56736cde676621ea8b404f024d8e51d879677ee09R17 with proper GFK field handling.
So now, the content type and object id should be filled from the provided content object.

PR Checklist

  • Change is covered with tests
  • CHANGELOG.md is updated if needed

@amureki amureki self-assigned this Aug 16, 2024
@amureki amureki merged commit 9f9c0e3 into main Aug 16, 2024
9 checks passed
@amureki amureki deleted the 488/align-gfk-fields branch August 16, 2024 12:55
Comment on lines +702 to +707
setattr(
instance,
content_type_field,
contenttypes_models.ContentType.objects.get_for_model(value),
)
setattr(instance, object_id_field, value.pk)
Copy link
Contributor

Choose a reason for hiding this comment

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

After this change, null values for a generic foreign key (where both the content_type and object_id fields are nullable) fail here. I believe this section should be skipped when value is None.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm, you are right!

I have drafted #496 to address that, however it would not prevent content_type and object_id from generating random values in case they are not nullable and content_object is None.
(This was never a case before either, so I am not sure how critical it is to cover now - as it is not easy).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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.

2 participants