Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#20984 closed Bug (fixed)

sqlite3 adaptors tries to "decode" str value when running on Python 3

Reported by: lvella@… 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 Claude Paroz, 11 years ago

Easy pickings: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

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:).

comment:2 by Claude Paroz <claude@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 169637649baa012a8a77b17465c5c0c1085336ea:

Fixed #20984 -- Stopped decoding bytes in sqlite3 adapter on Python 3

Thanks lvella at gmail.com for the report.

comment:3 by Claude Paroz <claude@…>, 11 years ago

In 58157be5ad31b42a1dc73e357cfdece02fd0b6ee:

[1.6.x] Fixed #20984 -- Stopped decoding bytes in sqlite3 adapter on Python 3

Thanks lvella at gmail.com for the report.
Backport of 169637649 from master.

Note: See TracTickets for help on using tickets.
Back to Top