Changes between Initial Version and Version 2 of Ticket #28727


Ignore:
Timestamp:
10/20/2017 09:52:44 AM (20 months ago)
Author:
direx
Comment:

OK, I have updated the original text in the ticket to include the full stracktrace.

Replying to Simon Charette:

Also, I think you'd want to use annotate(today=Value(datetime.date.today())) instead.

Actually I am doing something entirely different (I need Coalesce() and Max()) and ran into this issue right there. The above code is just a minimum demonstration on how the bug can be triggered. I know that the code doesn't actually make sense, but I did not want to make the generated query more complex than it has to be for the example.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28727 – Description

    initial v2  
    77from django.db.models.functions import Cast
    88
     9User.objects.get_or_create(username="test")
    910User.objects.all().annotate(today=Cast(datetime.date.today(), models.DateField()))
    1011
    11 ...
     12Traceback (most recent call last):
     13  File "<console>", line 1, in <module>
     14  File "/tmp/testenv/lib/python2.7/site-packages/django/db/models/query.py", line 226, in __repr__
     15    data = list(self[:REPR_OUTPUT_SIZE + 1])
     16  File "/tmp/testenv/lib/python2.7/site-packages/django/db/models/query.py", line 250, in __iter__
     17    self._fetch_all()
     18  File "/tmp/testenv/lib/python2.7/site-packages/django/db/models/query.py", line 1118, in _fetch_all
     19    self._result_cache = list(self._iterable_class(self))
     20  File "/tmp/testenv/lib/python2.7/site-packages/django/db/models/query.py", line 62, in __iter__
     21    for row in compiler.results_iter(results):
     22  File "/tmp/testenv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 842, in results_iter
     23    row = self.apply_converters(row, converters)
     24  File "/tmp/testenv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 827, in apply_converters
     25    value = converter(value, expression, self.connection, self.query.context)
     26  File "/tmp/testenv/lib/python2.7/site-packages/django/db/backends/sqlite3/operations.py", line 227, in convert_datefield_value
     27    value = parse_date(value)
     28  File "/tmp/testenv/lib/python2.7/site-packages/django/utils/dateparse.py", line 61, in parse_date
     29    match = date_re.match(value)
     30TypeError: expected string or buffer
    1231
    13 TypeError: expected string or buffer
    1432}}}
    1533
Back to Top