#34816: GenericForeignKey crashes if content_type_id is changed and object_id is
type incompatible with old object
--------------------------------------+------------------------------------
     Reporter:  Richard Laager        |                    Owner:  nobody
         Type:  Bug                   |                   Status:  new
    Component:  contrib.contenttypes  |                  Version:  4.2
     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
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

 * type:  Uncategorized => Bug
 * stage:  Unreviewed => Accepted


Comment:

 I was able to reproduce the issue with the following test:
 {{{#!diff
 diff --git a/tests/generic_relations_regress/tests.py
 b/tests/generic_relations_regress/tests.py
 index b7ecb499eb..7b7883ee88 100644
 --- a/tests/generic_relations_regress/tests.py
 +++ b/tests/generic_relations_regress/tests.py
 @@ -314,6 +314,18 @@ class GenericRelationTests(TestCase):
          result = Link.objects.filter(places=place)
          self.assertCountEqual(result, [link])

 +    def test_1(self):
 +        from django.contrib.contenttypes.models import ContentType
 +
 +        board = Board.objects.create(name="some test")
 +        oddrel = OddRelation1.objects.create(name="clink")
 +        charlink = CharLink.objects.create(content_object=oddrel)
 +        charlink = CharLink.objects.get(pk=charlink.pk)
 +        charlink.content_object
 +        charlink.object_id = board.pk
 +        charlink.content_type_id =
 ContentType.objects.get_for_model(Board).id
 +        charlink.content_object
 +
      def test_generic_reverse_relation_with_abc(self):
          """
          The reverse generic relation accessor (targets) is created if the

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34816#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018a6eaa5b4d-3e1fc4e8-8636-4005-803b-9bc7370176b4-000000%40eu-central-1.amazonses.com.

Reply via email to