Fix new set of TypeErrors decoding a string in modeltests.basic

Issue #47 resolved
Nate Margono
created an issue

{{{

!python


File "/home/nm/django-dev/django-3k/build/tests/modeltests/basic/models.py", line ?, in modeltests.basic.models.test.API_TESTS
Failed example:
Article.objects.dates('pub_date', 'year')
Exception raised:
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run
compileflags, 1), test.globs)
File "<doctest modeltests.basic.models.
test.API_TESTS[72]>", line 1, in <module>
Article.objects.dates('pub_date', 'year')
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1278, in py3_displayhook
if not value:
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 110, in
bool__
next(iter(self))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 104, in _result_iter
self._fill_cache()
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 755, in _fill_cache
self._result_cache.append(next(self._iter))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 960, in results_iter
date = typecast_timestamp(str(date))
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 77, in typecast_timestamp
s = str(s, encoding='utf8')
TypeError: decoding str is not supported


File "/home/nm/django-dev/django-3k/build/tests/modeltests/basic/models.py", line ?, in modeltests.basic.models.test.API_TESTS
Failed example:
Article.objects.dates('pub_date', 'month')
Exception raised:
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run
compileflags, 1), test.globs)
File "<doctest modeltests.basic.models.
test.API_TESTS[73]>", line 1, in <module>
Article.objects.dates('pub_date', 'month')
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1278, in py3_displayhook
if not value:
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 110, in
bool__
next(iter(self))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 104, in _result_iter
self._fill_cache()
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 755, in _fill_cache
self._result_cache.append(next(self._iter))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 960, in results_iter
date = typecast_timestamp(str(date))
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 77, in typecast_timestamp
s = str(s, encoding='utf8')
TypeError: decoding str is not supported


File "/home/nm/django-dev/django-3k/build/tests/modeltests/basic/models.py", line ?, in modeltests.basic.models.test.API_TESTS
Failed example:
Article.objects.dates('pub_date', 'day')
Exception raised:
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run
compileflags, 1), test.globs)
File "<doctest modeltests.basic.models.
test.API_TESTS[74]>", line 1, in <module>
Article.objects.dates('pub_date', 'day')
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1278, in py3_displayhook
if not value:
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 110, in
bool__
next(iter(self))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 104, in _result_iter
self._fill_cache()
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 755, in _fill_cache
self._result_cache.append(next(self._iter))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 960, in results_iter
date = typecast_timestamp(str(date))
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 77, in typecast_timestamp
s = str(s, encoding='utf8')
TypeError: decoding str is not supported


File "/home/nm/django-dev/django-3k/build/tests/modeltests/basic/models.py", line ?, in modeltests.basic.models.test.API_TESTS
Failed example:
Article.objects.dates('pub_date', 'day', order='ASC')
Exception raised:
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run
compileflags, 1), test.globs)
File "<doctest modeltests.basic.models.
test.API_TESTS[75]>", line 1, in <module>
Article.objects.dates('pub_date', 'day', order='ASC')
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1278, in py3_displayhook
if not value:
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 110, in
bool__
next(iter(self))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 104, in _result_iter
self._fill_cache()
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 755, in _fill_cache
self._result_cache.append(next(self._iter))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 960, in results_iter
date = typecast_timestamp(str(date))
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 77, in typecast_timestamp
s = str(s, encoding='utf8')
TypeError: decoding str is not supported


File "/home/nm/django-dev/django-3k/build/tests/modeltests/basic/models.py", line ?, in modeltests.basic.models.test.API_TESTS
Failed example:
Article.objects.dates('pub_date', 'day', order='DESC')
Exception raised:
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run
compileflags, 1), test.globs)
File "<doctest modeltests.basic.models.
test.API_TESTS[76]>", line 1, in <module>
Article.objects.dates('pub_date', 'day', order='DESC')
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1278, in py3_displayhook
if not value:
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 110, in
bool__
next(iter(self))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 104, in _result_iter
self._fill_cache()
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 755, in _fill_cache
self._result_cache.append(next(self._iter))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 960, in results_iter
date = typecast_timestamp(str(date))
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 77, in typecast_timestamp
s = str(s, encoding='utf8')
TypeError: decoding str is not supported


File "/home/nm/django-dev/django-3k/build/tests/modeltests/basic/models.py", line ?, in modeltests.basic.models.test.API_TESTS
Failed example:
Article.objects.dates()
Expected:
Traceback (most recent call last):
...
TypeError: dates() takes at least 3 arguments (1 given)
Got:
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run
compileflags, 1), test.globs)
File "<doctest modeltests.basic.models.
test__.API_TESTS[77]>", line 1, in <module>
Article.objects.dates()
File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 123, in dates
return self.get_query_set().dates(args, *kwargs)
TypeError: dates() takes at least 3 positional arguments (1 given)


File "/home/nm/django-dev/django-3k/build/tests/modeltests/basic/models.py", line ?, in modeltests.basic.models.test.API_TESTS
Failed example:
Article.objects.dates('invalid_field', 'year')
Expected:
Traceback (most recent call last):
...
FieldDoesNotExist: Article has no field named 'invalid_field'
Got:
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run
compileflags, 1), test.globs)
File "<doctest modeltests.basic.models.
test__.API_TESTS[78]>", line 1, in <module>
Article.objects.dates('invalid_field', 'year')
File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 123, in dates
return self.get_query_set().dates(args, *kwargs)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 521, in dates
_field_name=field_name, _kind=kind, _order=order)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 744, in _clone
c._setup_query()
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 985, in _setup_query
field = self.model._meta.get_field(self._field_name, many_to_many=False)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/options.py", line 277, in get_field
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, name))
django.db.models.fields.FieldDoesNotExist: Article has no field named 'invalid_field'


File "/home/nm/django-dev/django-3k/build/tests/modeltests/basic/models.py", line ?, in modeltests.basic.models.test.API_TESTS
Failed example:
for a in Article.objects.dates('pub_date', 'day', order='DESC').iterator():
print(repr(a))
Exception raised:
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run
compileflags, 1), test.globs)
File "<doctest modeltests.basic.models.
test__.API_TESTS[81]>", line 1, in <module>
for a in Article.objects.dates('pub_date', 'day', order='DESC').iterator():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 960, in results_iter
date = typecast_timestamp(str(date))
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 77, in typecast_timestamp
s = str(s, encoding='utf8')
TypeError: decoding str is not supported


}}}

Comments (2)

  1. Nate Margono reporter

    Ok, so my fix to issue #44 will convert s to type str, even if it's already of that type -- hence py3 will raise "TypeError: decoding str is not supported" error. So, I simply add another condition on the if-statement in typecast_timestamp() to ensure that s is not a str to begin with. This issue is now closed.

  2. Log in to comment