#35965: GenericForeignKeys lose the assigned unsaved object after the object is
saved
--------------------------------------+------------------------------------
Reporter: Willem Van Onsem | Owner: (none)
Type: Bug | Status: new
Component: contrib.contenttypes | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Brock Smickley):
Replying to [comment:1 Sarah Boyce]:
> Thank you for the report!
>
> Here is a potential test. The `tagged_item.save()` call currently raises
an error `django.db.utils.IntegrityError: NOT NULL constraint failed:
generic_relations_taggeditem.object_id`
> {{{#!diff
> diff --git a/tests/generic_relations/tests.py
b/tests/generic_relations/tests.py
> index e0c6fe2db7..32c90f2290 100644
> --- a/tests/generic_relations/tests.py
> +++ b/tests/generic_relations/tests.py
> @@ -626,6 +626,13 @@ class GenericRelationsTests(TestCase):
> with self.assertRaisesMessage(ValueError, msg):
> tagged_item.save()
>
> + def test_unsaved_generic_foreign_key_save(self):
> + quartz = Mineral(name="Quartz", hardness=7)
> + tagged_item = TaggedItem(tag="shiny", content_object=quartz)
> + quartz.save()
> + tagged_item.save()
> + self.assertEqual(tagged_item.content_object, quartz)
> +
> @skipUnlessDBFeature("has_bulk_insert")
> def test_unsaved_generic_foreign_key_parent_bulk_create(self):
> }}}
wait, do we actually want this test to pass? or do we want a similar test
with a `ForeignKey` to fail?
--
Ticket URL: <
https://code.djangoproject.com/ticket/35965#comment:3>