Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#11975 closed (fixed)

invalid sql returned from django.db.backends.sqlite3.DatabaseOperations.date_trunc_sql

Reported by: akonsu@… Owned by: Fabián Ezequiel Gallina
Component: Database layer (models, ORM) Version: master
Severity: Keywords: sqlite DatabaseOperations pycamp2010 djangosprint famaf
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


this method returns 'django_date_trunc("<precision>", <field>)'. in sqlite3, double quoted strings are identifiers, and string literals are single quoted (see so it should return "django_date_trunc('<precision>', <field>)". this breaks code such as the following:

MyModel.objects.extra(select={'year':connection.ops.date_trunc_sql('year', '"mymodel"."date"')}).values('year').order_by().annotate(total=Count('pk')) 

the resulting query:

[{'time': '0.007', 'sql': u'SELECT (django_date_trunc("year", "mymodel"."date")) AS "year", COUNT("mymodel"."id") AS "total" FROM "mymodel" GROUP BY django_date_trunc("year", "mymodel"."date")'}] 

same problem exists with date_extract_sql()

Attachments (1)

bug11975.patch (2.0 KB) - added by Fabián Ezequiel Gallina 7 years ago.
Tests for bug #11975

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by Russell Keith-Magee

milestone: 1.2
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 7 years ago by Fabián Ezequiel Gallina

Owner: changed from nobody to Fabián Ezequiel Gallina

comment:3 Changed 7 years ago by Fabián Ezequiel Gallina

Resolution: fixed
Status: newclosed

I was not able to reproduce this issue. My guess is that it was fixed in this revision[0].

Attached is a patch which adds a test for this bug.


comment:4 Changed 7 years ago by Fabián Ezequiel Gallina

Has patch: set

comment:5 Changed 7 years ago by Fabián Ezequiel Gallina

Keywords: pycamp2010 djangosprint famaf added

Changed 7 years ago by Fabián Ezequiel Gallina

Attachment: bug11975.patch added

Tests for bug #11975

comment:6 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top