#34816: GenericForeignKey crashes if content_type_id is changed and object_id is
type incompatible with old object
-------------------------------------+-------------------------------------
     Reporter:  Richard Laager       |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:                       |                  Version:  4.2
  contrib.contenttypes               |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * status:  new => closed
 * has_patch:  1 => 0
 * resolution:   => invalid


Comment:

 Thanks for this report, however, as far as I'm aware it's an issue in your
 code:
 {{{#!python
     a.content_type_id = ContentType.objects.get_for_model(B)
     a.object_id = "foo"
 }}}
 You should assign `id` to the `content_type_id`, not a content type
 instance. Using:
 {{{#!python
     a.content_type_id = ContentType.objects.get_for_model(B).id
     a.object_id = "foo"
 }}}
 or
 {{{#!python
     a.content_type = ContentType.objects.get_for_model(B)
     a.object_id = "foo"
 }}}
 works for me.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34816#comment:1>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018a6dc3c4b9-5c888b30-7c76-4f42-9550-a56408bc4455-000000%40eu-central-1.amazonses.com.

Reply via email to