[Django] #29442: wrong sql for cast datetime to date in sqlite backend

2 views
Skip to first unread message

Django

unread,
May 25, 2018, 7:21:30 AM5/25/18
to django-...@googlegroups.com
#29442: wrong sql for cast datetime to date in sqlite backend
-------------------------------------+-------------------------------------
Reporter: Mauro | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords: sqlite3 cast
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
"data_dimissione" is datetime field and I need list of days, so my
queryset is like

qs = objects.all().annotate(date_only=Cast("data_dimissione",
DateField())).values_list('date_only', flat=True).distinct()

It works on mysql , but django 1.11.10-1~bpo9+1 with sqlite3
3.16.2-5+deb9u1 raise TypeError
{{{
.....
File "../site-packages/django/db/backends/sqlite3/operations.py", line
232, in convert_datefield_value
raise e
TypeError: expected string or buffer
}}}

Reason is sql query is like

SELECT DISTINCT CAST("ps_ps"."data_dimissione" AS date) AS "date_only",
........

but data results is
2018|......
see https://code.djangoproject.com/ticket/28727#comment:6


Correct sql seems
SELECT DISTINCT date("ps_ps"."data_dimissione" ) AS "date_only", .

--
Ticket URL: <https://code.djangoproject.com/ticket/29442>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 25, 2018, 2:49:17 PM5/25/18
to django-...@googlegroups.com
#29442: wrong sql for cast datetime to date in sqlite backend
-------------------------------------+-------------------------------------
Reporter: Mauro | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: sqlite3 cast | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #28727 (fixed in Django 2.1).

--
Ticket URL: <https://code.djangoproject.com/ticket/29442#comment:1>

Reply all
Reply to author
Forward
0 new messages