Fix TypeError in modeltests.basic

Issue #44 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:
a.save()
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[9]>", line 1, in <module>
a.save()
File "/usr/local/lib/python3.1/dist-packages/django/db/models/base.py", line 438, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/base.py", line 500, in save_base
manager.using(using).filter(pk=pk_val).exists())):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 491, in exists
return self.query.has_results(using=self.db)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/query.py", line 386, in has_results
return bool(compiler.execute_sql(SINGLE))
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


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.all()
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[10]>", line 1, in <module>
Article.objects.all()
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/query.py", line 267, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 678, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


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.get(idexact=1)
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[11]>", line 1, in <module>
Article.objects.get(idexact=1)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(args, *kwargs)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 334, in get
num = len(clone)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 79, in
len__
self._result_cache = list(self.iterator())
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 267, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 678, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


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.get(headlinestartswith='Area woman')
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[12]>", line 1, in <module>
Article.objects.get(headline__startswith='Area woman')
File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(args, *kwargs)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 339, in get
% self.model._meta.object_name)
modeltests.basic.models.DoesNotExist: Article matching query does not exist.


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.get(pub_dateyear=2005)
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[13]>", line 1, in <module>
Article.objects.get(pub_dateyear=2005)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(args, *kwargs)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 334, in get
num = len(clone)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 79, in
len__
self._result_cache = list(self.iterator())
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 267, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 678, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


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.get(pub_dateyear=2005, pub_datemonth=7)
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[14]>", line 1, in <module>
Article.objects.get(pub_date
year=2005, pub_datemonth=7)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(args, *kwargs)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 334, in get
num = len(clone)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 79, in
len__
self._result_cache = list(self.iterator())
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 267, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 678, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


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.get(pub_dateyear=2005, pub_datemonth=7, pub_dateday=28)
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[15]>", line 1, in <module>
Article.objects.get(pub_dateyear=2005, pub_datemonth=7, pub_dateday=28)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(args, *kwargs)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 334, in get
num = len(clone)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 79, in
len__
self._result_cache = list(self.iterator())
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 267, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 678, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


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.get(pub_dateweek_day=5)
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[16]>", line 1, in <module>
Article.objects.get(pub_dateweek_day=5)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(args, *kwargs)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 334, in get
num = len(clone)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 79, in
len__
self._result_cache = list(self.iterator())
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 267, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 678, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


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.get(id=1)
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[17]>", line 1, in <module>
Article.objects.get(id=1)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(args, *kwargs)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 334, in get
num = len(clone)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 79, in
len__
self._result_cache = list(self.iterator())
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 267, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 678, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


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.get(headline='Area woman programs in Python')
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[18]>", line 1, in <module>
Article.objects.get(headline='Area woman programs in Python')
File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(args, *kwargs)
File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 339, in get
% self.model._meta.object_name)
modeltests.basic.models.DoesNotExist: Article matching query does not exist.


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.filter(pub_dateyear=2005)
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[19]>", line 1, in <module>
Article.objects.filter(pub_dateyear=2005)
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/query.py", line 267, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 678, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


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.filter(pub_dateyear=2005, pub_datemonth=7)
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[21]>", line 1, in <module>
Article.objects.filter(pub_date
year=2005, pub_datemonth=7)
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/query.py", line 267, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 678, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


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.filter(pub_dateweek_day=5)
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[22]>", line 1, in <module>
Article.objects.filter(pub_dateweek_day=5)
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/query.py", line 267, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 678, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python3.1/dist-packages/django/db/models/sql/compiler.py", line 733, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/sqlite3/base.py", line 198, in execute
return Database.Cursor.execute(self, query, params)
File "/usr/local/lib/python3.1/dist-packages/django/db/backends/util.py", line 73, in typecast_timestamp
if not ' ' in s: return typecast_date(s)
TypeError: Type str doesn't support the buffer API


}}}

Comments (3)

  1. Nate Margono reporter
    • changed status to resolved
    • removed component

    The issue lies in the bytestring-to-string conversion (similar to Andrew's #39). In this case, the if-statement within typecast_timestamp() will fail and consequently will not invoke typecast_date(), which also does the same conversion in Andrew's fix. So, I simply enforce the conversion of bytestring s to string, before doing any computation.

    This also fixes the TypeError's in modeltests.field_defaults as Andrew mentioned to me, and it now passes. So, I won't bother opening up a new issue for that.

    This issue has been resolved.

  2. Log in to comment