Here's the query I'm trying to run:
MyModel.objects.filter(created__lt=functions.TruncDay(Value(timezone.now(), output_field=DateTimeField())))It translates to:
SELECT <field-list> FROM "mymodel" WHERE "mymodel"."created" < (DATE_TRUNC('day', %%s AT TIME ZONE %s))before Django performs parameter substitution. Note that the first %s has been escaped to %%s. This causes the parameter substitution to throw an exception.
Is this intended behaviour or a bug?
I dug into the internals a bit to figure this out and the issue comes from this line where the query till that point is escaped but later, they are never escaped back to the original form for correct parameter substitution. I went ahead and added code to replace `%%s` with `%s` before parameter substitution and it worked fine. Am I missing something here or should I file a bug(has it been filed already?)?