Opened 6 years ago

Closed 6 years ago

#29840 closed Bug (invalid)

DJANGO query generated by ORM is invalid

Reported by: Arjunsingh Owned by: Arjunsingh
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords: django orm query
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Simon Charette)

I have a django query which compares datetime like this -

filters = {'order_created_on__gte':'2018-10-10'}
queryset = model.objects.filter(**filters)
query = str(queryset.query)

It creates a query - select ... where order_created_on >= 2018-10-10 00:00:00

When fired on postgres, it gives an error - syntax error at or near "00".

If I fire the same query in db manually by replacing the date by '2018-10-10' it works.

Now I actually tried the following ways, but all queries give the same text in the db query

filters = {'order_created_on__gte':datetime(2018-10-10)}
filters = {'order_created_on__year__gte':2018, 'order_created_on__month__gte':10, 'order_created_on__day__gte':10}

Also used the range filter, all of the above insert this text in the final query -

where order_created_on >= 2018-10-10 00:00:00

Updating the time zone too didnt have any effect rather than just removing a +5:30 from the query.
And the UI over here aint showing 'double underscores used in filters

Change History (4)

comment:1 by Arjunsingh, 6 years ago

Owner: changed from nobody to Arjunsingh
Status: newassigned

comment:2 by Arjunsingh, 6 years ago

Description: modified (diff)

comment:3 by Arjunsingh, 6 years ago

Description: modified (diff)

comment:4 by Simon Charette, 6 years ago

Description: modified (diff)
Resolution: invalid
Status: assignedclosed

Hello there,

First str(queryset.query) is not guaranteed to return a valid SQL string; it's only meant to be used for debugging purpose.

Next it's not clear if Django is at fault unless you can provide a traceback and a reproduction case. From my understanding of your report it seems like you are experiencing these errors when manually running the debugging SQL provided by str(queryset.query) so I'm going to close as invalid for now.

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