Python 3.6 compatibility: bytes vs strings stuff

These changes mostly revolve around the change in ObjectId constructor
when running on Python 3.6. Where on 2.7 the constructor would accept
12- and 24-byte strings, now only 12-byte bytes and 24-character strings
are accepted. Good thing, but required some changes in our code.

Other changes include hashing of strings, which isn't supported, so they
are converted to bytes first, and sometimes converted back afterwards.
This commit is contained in:
2017-03-03 14:14:36 +01:00
parent c2206e6b27
commit 2e41c074b5
12 changed files with 62 additions and 46 deletions

View File

@@ -136,7 +136,7 @@ def str2id(document_id):
try:
return bson.ObjectId(document_id)
except bson.objectid.InvalidId:
except (bson.objectid.InvalidId, TypeError):
log.debug('str2id(%r): Invalid Object ID', document_id)
raise wz_exceptions.BadRequest('Invalid object ID %r' % document_id)