loads() sometimes broken

Issue #2698 resolved
Former user created an issue

Under Python 3.2.3 (and probably all Python 3 versions), the loads() method can choke if it ever needs to call the persistent_load(id) function.

If following the serialize tutorial at http://docs.sqlalchemy.org/en/rel_0_8/core/serializer.html, SQLAlchemy may choke if you have serialized some query objects. I think I've tracked this down... because Python 3 now differentiates between strings and binary strings, the line

m = our_ids.match(id)

can fail with a

TypeError: can't use a string pattern on a bytes-like object

since id is a binary string from pickler.

The solution seems to be simple... Change this:

...
 def persistent_load(id):
        m = our_ids.match(id)
        if not m:
            return None
        else:
...

to this:

...
 def persistent_load(id):
# start Py3K
        id = str(id)
# end Py3K
        m = our_ids.match(id)
        if not m:
            return None
        else:
...

Comments (3)

  1. Log in to comment