#19722: GenericRelation in a subclass, filtering by a field of the GFK-declaring
model fails
------------------------------------------------+------------------------
               Reporter:  ramiro                |          Owner:  nobody
                   Type:  Bug                   |         Status:  new
              Component:  contrib.contenttypes  |        Version:  master
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  0
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 This was report in a comment by user 'nator' to #11263, is a different
 issue to the one initially discussed in that ticket. Quoting:

 ''Say we have a non-abstract superclass and a subclass, and we add a GR
 relationship to the subclass:''
 {{{
 class Order(models.Model):
     content_type = models.ForeignKey(ContentType)
     object_id = models.PositiveIntegerField()
     content_object = generic.GenericForeignKey()
     status = models.CharField(max_length=10, default='ordered')

 class Media(models.Model):
     order = generic.GenericRelation(Order)

 class Photo(Media):
     title = models.CharField()

 Photo.objects.filter(order__status='ordered').count()
 --> doesn't break, but always returns 0.
 }}}

 ''The basic problem is that when the Order object is created Django
 inserts it into the DB using the content_type of Photo, but when the
 select is run Django realizes Order actually lives in Media and tries to
 use that content_type. So the inserts all "work", but the count() never
 finds them. It's a mismatch between the content_type_id when it runs the
 insert and select.

 After digging through django/config/contenttypes/generic.py a bit I feel
 like the correct answer is to change the inserts to use the content_type
 of the class that actually contains the m2m relationship. (Media, in this
 case).''

 There is a proposed fix attached to that ticket.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19722>
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 post to this group, send email to django-updates@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to