Take the 2-minute tour ×

I am migrating a web app from Python 2.5 runtime to Python 2.7. My app stores pickled data into the database, and when unpickling what I stored I have some issues with long integers:

An int like 100003087328067, pickled using Python 2.5, gets unpickled to 2147483647 (which is 2^31-1) under Python 2.7.

How to retrieve the right value?

Can there be other issues? With str encoding for instance? (I found this but it's with python 3: Unpicking data pickled in Python 2.5, in Python 3.1 then uncompressing with zlib)

More about my context: I am migrating a Google App Engine app, and I stored my data using a custom db.Property that acts a bit like the NDB PickleProperty.

share|improve this question
by the way, is this a pickle issue? I can read in the docs: The pickle serialization format is guaranteed to be backwards compatible across Python releases (here) –  Alexis Feb 16 '12 at 16:21
Agreed it sounds fishy. Probably the Python 2.7 is built with 32-bit ints while the 2.5 is built with 64-bit ints. Did you get this result in production or using the dev appserver? –  Guido van Rossum Feb 17 '12 at 4:01
Not that I can reproduce this or necessarily believe it is a bug in pickle -- could you show an example pickle that has this value (using the repr() function) and the code you use to unpickle it? –  Guido van Rossum Feb 17 '12 at 4:08
Thanks, I can reproduce this, and it surely looks like a bug in the Py27 runtime. I'll raise this internally. –  Guido van Rossum Feb 19 '12 at 0:58
Good news. Our Python 2.7 engineering team has tracked down the bug and a fix is on the way, slated for inclusion in the 1.6.3 runtime to be released later this month. Thanks @Alexis for reporting this and for providing me with a reproducible test case! –  Guido van Rossum Feb 21 '12 at 18:37
show 2 more comments

1 Answer

I would suggest a two stage setup:

Write a Python 2.5 script to unpickle the current values, store them with a common format like JSON, then read it back into a Python 2.7 app.

Ideally, continue to use a format like JSON rather than pickling, so that it isn't dependant on the platform in the future. Even better, store the data in the database as properly normalised data, so it can be used even more easily.

share|improve this answer
Indeed we plan to use JSON more extensively, and there are only a few places where we have non-json-like data stored. So it may be the opportunity to make that change sooner... –  Alexis Feb 16 '12 at 15:09
add comment

Your Answer


