﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21434	IN clause not supporting the to_field	berndtj@…	nobody	"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.



"	Bug	closed	Database layer (models, ORM)	1.5	Normal	fixed		Baptiste Mispelon	Unreviewed	0	0	0	0	0	0
