[Django] #29840: DJANGO query generated by ORM is invalid

3 views
Skip to first unread message

Django

unread,
Oct 11, 2018, 6:49:53 AM10/11/18
to django-...@googlegroups.com
#29840: DJANGO query generated by ORM is invalid
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
Arjunsingh |
Type: Bug | Status: new
Component: Database | Version: 2.1
layer (models, ORM) |
Severity: Normal | Keywords: django orm query
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

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

Django

unread,
Oct 11, 2018, 6:50:47 AM10/11/18
to django-...@googlegroups.com
#29840: DJANGO query generated by ORM is invalid
-------------------------------------+-------------------------------------
Reporter: Arjunsingh | Owner:
| Arjunsingh
Type: Bug | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:

Keywords: django orm query | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

* owner: nobody => Arjunsingh
* status: new => assigned


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

Django

unread,
Oct 11, 2018, 6:52:11 AM10/11/18
to django-...@googlegroups.com
#29840: DJANGO query generated by ORM is invalid
-------------------------------------+-------------------------------------
Reporter: Arjunsingh | Owner:
| Arjunsingh
Type: Bug | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: django orm query | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Arjunsingh:

Old description:

> 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.

New description:

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 '__' used in filters

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29840#comment:2>

Django

unread,
Oct 11, 2018, 6:54:41 AM10/11/18
to django-...@googlegroups.com
#29840: DJANGO query generated by ORM is invalid
-------------------------------------+-------------------------------------
Reporter: Arjunsingh | Owner:
| Arjunsingh
Type: Bug | Status: assigned
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: django orm query | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Arjunsingh:

Old description:

> 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 '__' used in filters

New description:

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 underscore''s used in filters

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29840#comment:3>

Django

unread,
Oct 11, 2018, 8:28:11 AM10/11/18
to django-...@googlegroups.com
#29840: DJANGO query generated by ORM is invalid
-------------------------------------+-------------------------------------
Reporter: Arjunsingh | Owner:
| Arjunsingh
Type: Bug | Status: closed

Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: django orm query | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

* status: assigned => closed
* resolution: => invalid


Old description:

> 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 underscore''s used in filters

New description:

I have a django query which compares datetime like this -

{{{#!python


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

{{{#!python


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 -

{{{#!sql


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 underscore''s used in filters

--

Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29840#comment:4>

Reply all
Reply to author
Forward
0 new messages