#21434: IN clause not supporting the to_field
-------------------------------+--------------------
     Reporter:  berndtj@…      |      Owner:  nobody
         Type:  Bug            |     Status:  new
    Component:  Uncategorized  |    Version:  1.5
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 I think this is similar to bug 17972.

 If I have a model defined:


 {{{
    class VolumeTemplate(models.Model):
        parent = models.ForeignKey(
           'Volume', null=True, blank=True, to_field='uuid',
 related_name='parent_templates')

    class BracketVolume(models.Model):
        uuid = UUIDField(version=4, auto=True, db_index=True, unique=True)
 }}}

 The following query returns an empty result set, even if the parent is non
 None:

 {{{
    queryset = Volume.objects.all()
    VolumeTemplate.objects.filter(parent__in=queryset)
 }}}

 However the following will return the corresponding VolumeTemplates:

 {{{
     VolumeTemplate.objects.filter(parent__pk__in=queryset)
 }}}

 This is because the subquery generated by the IN clause does not take the
 to_field into consideration and instead returns a list of Volume.id values
 instead of Volume.uuid values.  The SQL is comparing the parent_id which
 is a UUID field due to the to_field.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21434>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/060.435929efa8687b6f17f2ee7e1d8261a0%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to