#24837: Unable to query DateField using DateRange
----------------------------------+--------------------------------------
     Reporter:  schinckel         |                    Owner:
         Type:  Uncategorized     |                   Status:  new
    Component:  contrib.postgres  |                  Version:  1.8
     Severity:  Normal            |               Resolution:
     Keywords:                    |             Triage Stage:  Unreviewed
    Has patch:  0                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  1                 |                    UI/UX:  0
----------------------------------+--------------------------------------
Changes (by schinckel):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 I have a partial implementation, showing the next possible issue.

 That is, the date field is attempting to coerce the lookup value into a
 date:

 {{{
 ======================================================================
 ERROR: test_datetime_range
 (postgres_tests.test_ranges.TestQueringWithRanges)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File
 "/Users/matt/Development/django/tests/postgres_tests/test_ranges.py", line
 238, in test_datetime_range
 
RangeLookupsModel.objects.filter(timestamp__contained_by=DateTimeTZRange('2015-01-01T09:00',
 '2015-05-04T23:55')),
   File "/Users/matt/Development/django/django/db/models/manager.py", line
 125, in manager_method
     return getattr(self.get_queryset(), name)(*args, **kwargs)
   File "/Users/matt/Development/django/django/db/models/query.py", line
 781, in filter
     return self._filter_or_exclude(False, *args, **kwargs)
   File "/Users/matt/Development/django/django/db/models/query.py", line
 799, in _filter_or_exclude
     clone.query.add_q(Q(*args, **kwargs))
   File "/Users/matt/Development/django/django/db/models/sql/query.py",
 line 1236, in add_q
     clause, _ = self._add_q(q_object, self.used_aliases)
   File "/Users/matt/Development/django/django/db/models/sql/query.py",
 line 1262, in _add_q
     allow_joins=allow_joins, split_subq=split_subq,
   File "/Users/matt/Development/django/django/db/models/sql/query.py",
 line 1196, in build_filter
     condition = self.build_lookup(lookups, col, value)
   File "/Users/matt/Development/django/django/db/models/sql/query.py",
 line 1095, in build_lookup
     return final_lookup(lhs, rhs)
   File "/Users/matt/Development/django/django/db/models/lookups.py", line
 98, in __init__
     self.rhs = self.get_prep_lookup()
   File "/Users/matt/Development/django/django/db/models/lookups.py", line
 136, in get_prep_lookup
     return self.lhs.output_field.get_prep_lookup(self.lookup_name,
 self.rhs)
   File
 "/Users/matt/Development/django/django/db/models/fields/__init__.py", line
 734, in get_prep_lookup
     return self.get_prep_value(value)
   File
 "/Users/matt/Development/django/django/db/models/fields/__init__.py", line
 1432, in get_prep_value
     value = super(DateTimeField, self).get_prep_value(value)
   File
 "/Users/matt/Development/django/django/db/models/fields/__init__.py", line
 1288, in get_prep_value
     return self.to_python(value)
   File
 "/Users/matt/Development/django/django/db/models/fields/__init__.py", line
 1391, in to_python
     parsed = parse_datetime(value)
   File "/Users/matt/Development/django/django/utils/dateparse.py", line
 93, in parse_datetime
     match = datetime_re.match(value)
 TypeError: expected string or buffer
 }}}

 https://github.com/schinckel/django/tree/query-with-ranges

--
Ticket URL: <https://code.djangoproject.com/ticket/24837#comment:1>
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/067.44824f065e86b9a01488051987fa6831%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to