Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Make sure we handle longs.
Browse files Browse the repository at this point in the history
Unforutnaly, MongoDB has a 64-bit limit. Sigh. We can later add a custom
serializer if we really have to.
  • Loading branch information
strichter committed Feb 12, 2014
1 parent 04ed0d2 commit 97486b0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mongopersist/interfaces.py
Expand Up @@ -23,7 +23,7 @@
from bson import objectid, dbref

MONGO_NATIVE_TYPES = (
bool, int, float, unicode, datetime.datetime, types.NoneType,
bool, int, long, float, unicode, datetime.datetime, types.NoneType,
objectid.ObjectId, dbref.DBRef)
REFERENCE_SAFE_TYPES = (
datetime.date, datetime.time, decimal.Decimal)
Expand Down
30 changes: 30 additions & 0 deletions src/mongopersist/tests/test_datamanager.py
Expand Up @@ -1290,6 +1290,36 @@ def doctest_MongoDataManager_no_compare():
"""


def doctest_MongoDataManager_long():
r"""MongoDataManager: Test behavior of long integers.
>>> dm.root['app'] = Root()
>>> dm.root['app'].x = 1L
>>> dm.tpc_finish(None)
Let's see how it is deserialzied?
>>> dm.root['app'].x
1L
Let's now create a really long integer:
>>> dm.root['app'].x = 2**62
>>> dm.tpc_finish(None)
>>> dm.root['app'].x
4611686018427387904L
And now an overly long one.
>>> dm.root['app'].x = 12345678901234567890L
>>> dm.tpc_finish(None)
Traceback (most recent call last):
...
OverflowError: MongoDB can only handle up to 8-byte ints
"""


def doctest_process_spec():
r"""process_spec(): General test
Expand Down
2 changes: 2 additions & 0 deletions src/mongopersist/tests/test_serialize.py
Expand Up @@ -313,6 +313,8 @@ def doctest_ObjectWriter_get_state_MONGO_NATIVE_TYPES():
>>> writer = serialize.ObjectWriter(None)
>>> writer.get_state(1)
1
>>> writer.get_state(1L)
1L
>>> writer.get_state(1.0)
1.0
>>> writer.get_state(u'Test')
Expand Down

0 comments on commit 97486b0

Please sign in to comment.