#20984 closed Bug (fixed)
sqlite3 adaptors tries to "decode" str value when running on Python 3
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Python 3 | Version: | 1.5 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
I ran into this error when I tried to execute Django on the experimental Pypy3 2.1 (yes, experimental over experimental), and luckly, due to a bug in Pypy support of Python 3, I think I found one on Django. CPython swallows exceptions raised inside sqlite3 adapters, Pypy didn't, thus I found that Django execute these lines, even on Python 3:
if Database.version_info >= (2, 4, 1):
# Starting in 2.4.1, the str type is not accepted anymore, therefore,
# we convert all str objects to Unicode
# As registering a adapter for a primitive type causes a small
# slow-down, this adapter is only registered for sqlite3 versions
# needing it (Python 2.6 and up).
Database.register_adapter(str, lambda s: s.decode('utf-8'))
Database.register_adapter(SafeBytes, lambda s: s.decode('utf-8'))
where the str adapter led to a fatal exception on experimental Pypy. But since unicode is str and str is bytes on Python 3 (and bytes is an alias to str on Python 2.6), the relevant line should be:
Database.register_adapter(bytes, lambda s: s.decode('utf-8'))
Or event be suppressed if on py3k... why would one be passing bytes to the database where it expects a string?
The same line is still there on master...
Change History (3)
comment:1 by , 12 years ago
| Easy pickings: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Bug |
comment:2 by , 12 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Confirmed that these adapters are not useful on Python 3 (test suite is passing without). I'd suggest to conditionally include them (
if not six.PY3:).