#9814: Python 2.6's sqlite refuses 8-bit SafeStrings
------------------------------------------+---------------------------------
Reporter: kmtracey | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: 1.0
Keywords: | Stage: Unreviewed
Has_patch: 0 |
------------------------------------------+---------------------------------
r9467/r9469 modified a test in modeltests/field_defaults to set a field
value to a utf-8 encoded !SafeString. This test now fails on Python 2.6
when using sqlite as the backend:
{{{
======================================================================
FAIL: Doctest: modeltests.field_defaults.models.__test__.API_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
File "d:\u\kmt\django\trunk\django\test\_doctest.py", line 2180, in
runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for
modeltests.field_defaults.models.__test__.API_TESTS
File "D:\u\kmt\django\trunk\tests\modeltests\field_defaults\models.py",
line unknown line number, in API_TESTS
----------------------------------------------------------------------
File "D:\u\kmt\django\trunk\tests\modeltests\field_defaults\models.py",
line ?, in modeltests.field_defaults.models.__test__.API_TESTS
Failed example:
a.save()
Exception raised:
Traceback (most recent call last):
File "d:\u\kmt\django\trunk\django\test\_doctest.py", line 1267, in
__run
compileflags, 1) in test.globs
File "<doctest
modeltests.field_defaults.models.__test__.API_TESTS[13]>", line 1, in
<module>
a.save()
File "d:\u\kmt\django\trunk\django\db\models\base.py", line 328, in
save
self.save_base(force_insert=force_insert,
force_update=force_update)
File "d:\u\kmt\django\trunk\django\db\models\base.py", line 379, in
save_base
rows = manager.filter(pk=pk_val)._update(values)
File "d:\u\kmt\django\trunk\django\db\models\query.py", line 435, in
_update
return query.execute_sql(None)
File "d:\u\kmt\django\trunk\django\db\models\sql\subqueries.py",
line 117, in execute_sql
cursor = super(UpdateQuery, self).execute_sql(result_type)
File "d:\u\kmt\django\trunk\django\db\models\sql\query.py", line
1756, in execute_sql
cursor.execute(sql, params)
File "d:\u\kmt\django\trunk\django\db\backends\sqlite3\base.py",
line 169, in execute
return Database.Cursor.execute(self, query, params)
ProgrammingError: You must not use 8-bit bytestrings unless you use a
text_factory that can interpret 8-bit bytestrings (like text_factory =
str). It is highly recommended that you instead just switch your
application to Unicode strings.
----------------------------------------------------------------------
Ran 1 test in 0.030s
FAILED (failures=1)
}}}
This can be fixed as regular `str` was fixed for Python 2.6 (r8276) by
adding `Database.register_adapter(SafeString, lambda s:s.decode('utf-8'))`
to the appropriate spot in django/db/sqlite3/base.py. That seems correct
but just in case I'm missing something I figured I'd check first before
just doing it. (I'm not entirely sure when app code would be sending
!SafeStrings to the DB, but I suppose it can happen and should be
supported?) Feedback?
--
Ticket URL: <http://code.djangoproject.com/ticket/9814>
Django <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---