﻿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
29891	Fix incorrect quoting in queryset.query	Timothy Allen	Timothy Allen	"This old ticket has some recent activity I have also run into with fields not being properly quoted in `queryset.query`:

https://code.djangoproject.com/ticket/14091

For a minimum example, start an app and create a model with a DateField:

{{{
from django.db import models

class BadDateModel(models.Model):
    my_date = models.DateField()
}}}

Then fire up a shell:

{{{
>>> q = BadDateModel.objects.filter(my_date__gt='1990-01-01')
>>> print(q.query)
SELECT ""bug_app_baddatemodel"".""id"", ""bug_app_baddatemodel"".""my_date"" FROM ""bug_app_baddatemodel"" WHERE ""bug_app_baddatemodel"".""my_date"" > 1990-01-01
}}}

As you can see, the generated query has a date value which is not quoted, which will cause an error when executed. This is causing me issues when trying to do an `EXECUTE {queryset.query}` to get an estimate of table size before performing certain DRF queries.

The error when it is executed against PostgreSQL: 

{{{
operator does not exist: date < integer
LINE 1: ... FROM ""blah"".""blah1"" WHERE (""blah"".""blah1"".""date"" < 1990-01-...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
}}}

I discovered this in PostgreSQL, but it seems to affect all backends; the repro above was done with SQLite."	Cleanup/optimization	closed	Database layer (models, ORM)	2.1	Normal	duplicate	queryset, orm		Accepted	1	0	1	1	0	0
