#24991: Range types not properly converted to SQL in QuerySet.query.__str__()
----------------------------------+------------------------------------
Reporter: unklphil | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Description changed by unklphil:
Old description:
> The string representation of the `QuerySet.query` object, which is useful
> in debugging, does not convert range types to their SQL equivalents,
> instead it just displays the string representation of the range type.
>
> {{{
> >>> import datetime
> >>> from django.utils.timezone import utc
> >>> from psycopg.extras import NumericRange, DateRange, DateTimeTZRange
> >>> from myapp.models import MyModel # model defintion is irrelevant
>
> >>> print(MyModel.objects.filter(num_rng__overlap=NumericRange(1, 5)))
> SELECT [...] FROM "myapp_mymodel" WHERE ("myapp_mymodel"."num_rng" &&
> NumericRange(1, 5, '[)'))
>
> >>>
> print(MyModel.objects.filter(date_rng__overlap=DateRange(datetime.date(2015,
> 5, 1), datetime.date(2015, 6, 1))))
> SELECT [...] FROM "myapp_mymodel" WHERE ("myapp_mymodel"."date_rng" &&
> DateRange(datetime.date(2015, 5, 1), datetime.date(2015, 6, 1), '[)'))
>
> >>>
> print(MyModel.objects.filter(dt_rng__overlap=DateTimeTZRange(datetime.datetime(2015,
> 5, 1, tzinfo=utc), datetime.datetime(2015, 6, 1, tzinfo=utc))))
> SELECT [...] FROM "myapp_mymodel" WHERE ("myapp_mymodel"."dt_rng" &&
> DateTimeTZRange(datetime.datetime(2015, 5, 1, 0, 0, tzinfo=<UTC>),
> datetime.datetime(2015, 6, 1, 0, 0, tzinfo=<UTC>), '[)'))
> }}}
>
> The expected output is `numrange(1.0, 5.0)`, `daterange('2015-05-01',
> '2015-06-01')` and `tstzrange('2015-05-01 00:00:00+00:00', '2015-06-01
> 00:00:00+00:00')` respectively.
New description:
The string representation of the `QuerySet.query` object, which is useful
in debugging, does not convert range types to their SQL equivalents,
instead it just displays the string representation of the range type.
{{{
>>> import datetime
>>> from django.utils.timezone import utc
>>> from psycopg.extras import NumericRange, DateRange, DateTimeTZRange
>>> from myapp.models import MyModel # model defintion is irrelevant
>>> print(MyModel.objects.filter(num_rng__overlap=NumericRange(1,
5)).query)
SELECT [...] FROM "myapp_mymodel" WHERE ("myapp_mymodel"."num_rng" &&
NumericRange(1, 5, '[)'))
>>>
print(MyModel.objects.filter(date_rng__overlap=DateRange(datetime.date(2015,
5, 1), datetime.date(2015, 6, 1))).query)
SELECT [...] FROM "myapp_mymodel" WHERE ("myapp_mymodel"."date_rng" &&
DateRange(datetime.date(2015, 5, 1), datetime.date(2015, 6, 1), '[)'))
>>>
print(MyModel.objects.filter(dt_rng__overlap=DateTimeTZRange(datetime.datetime(2015,
5, 1, tzinfo=utc), datetime.datetime(2015, 6, 1, tzinfo=utc))).query)
SELECT [...] FROM "myapp_mymodel" WHERE ("myapp_mymodel"."dt_rng" &&
DateTimeTZRange(datetime.datetime(2015, 5, 1, 0, 0, tzinfo=<UTC>),
datetime.datetime(2015, 6, 1, 0, 0, tzinfo=<UTC>), '[)'))
}}}
The expected output is `numrange(1.0, 5.0)`, `daterange('2015-05-01',
'2015-06-01')` and `tstzrange('2015-05-01 00:00:00+00:00', '2015-06-01
00:00:00+00:00')` respectively.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/24991#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.53df196eaa86ca02692222034e44e3be%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.