#32414: Syntax Error when combining __in and F() in filter
-------------------------------------+-------------------------------------
Reporter: dfrank8 | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Database | Version: 3.1
layer (models, ORM) |
Severity: Normal | Keywords: F()
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Similar to https://code.djangoproject.com/ticket/32151
I have a simple Google Calendar Events application. Profiles generate
calendar tokens with GSuite Oauth (not shown) that are used to make
CalendarEvents in my database (postgres:9.6). CalendarEvents queried via a
particular CalendarToken have the token's profile on the model. See
oversimplified example below:
{{{
class Profile(models.Model):
name = models.CharField(max_length=32)
class CalendarEvent(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE)
attendees = models.ManyToManyField(Profile, on_delete=models.CASCADE)
}}}
I'm trying to annotate whether a profile is "attending" the event, by
checking if the profile is in the attendees ManyToMany:
{{{
CalendarEvent.objects.annotate(
is_attending=Case(
When(
profile__in=F('attendees'),
then=Value(True)
),
default=Value(False),
output_field=models.BooleanField()
)
)
}}}
Generates an invalid syntax error (replacing db name with'' {APP}''):
{{{
ProgrammingError: syntax error at or near
""{APP}_calendarevent_attendees""
LINE 1: ...CASE WHEN ("{APP}_calendarevent"."profile_id" IN "{APP}_ca...
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32414>
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/050.482f7c8ddb5916298ea7e989acab93c6%40djangoproject.com.