Hello there,

This is a bug, there's an open Django issue for it [0].

I suggest you don't rely on Subquery for simple pk lookups. Django supported
direct query passing for as long as I can remember.

See https://groups.google.com/d/msg/django-users/aq7mL9Opd-s/z2LZ1jXlCAAJ 
for more details.

Cheers,
Simon

[0] https://code.djangoproject.com/ticket/28199

Le mardi 16 mai 2017 11:02:37 UTC-4, Алексей Широков a écrit :
>
> Guys help me figure it out.
>
> I use an example from the documentation
>
> https://docs.djangoproject.com/en/1.11/ref/models/expressions/#limiting-a-subquery-to-a-single-column
> >>> from datetime import timedelta
>
> >>> from django.utils import timezone
> >>> one_day_ago = timezone.now() - timedelta(days=1)
> >>> posts = Post.objects.filter(published_at__gte=one_day_ago)
> >>> Comment.objects.filter(post__in=Subquery(posts.values('pk')))
>
>
> But in my case 'pk' is `UUIDField()`
> When sql is compiled, `unification_cast_sql()` is called
>
> https://github.com/django/django/blob/stable/1.11.x/django/db/models/expressions.py#L980
>
> The result is the following
>
> ProgrammingError:
> SELECT ... FROM table WHERE id in (CAST(SELECT id FROM table2) AS uuid);
>
> Is this a bug or am I doing something wrong???
>
> Thank you.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bd9fb387-3af9-440a-a245-0dce17dc0e26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to