After further investigation the reason why this bug was hard to reproduce consistently is because it depends on how the 'simplejson' Python module was installed, and in particular whether its "speedups" C extension is available (but *not* on the version).
This also means it has nothing to do with the version of Python or psycopg2, even though trying to upgrade those may indirectly solve the issue if you happen to reinstall a different version of simplejson in the process.
The speedup-enabled version of simplejson will deserialize pure ASCII strings as plain str objects, whereas the pure Python implementation will always produce unicode objects regardless of the string contents.
The OpenERP framework was not ready to receive unicode strings for serialized binary/image fields, so it fails on any system where simplejson does not have the C extension installed.
You can check easily whether it is the case:
>>> # System has the speedup extension!
>>> import simplejson
>>> simplejson.decoder.c_scanstring is None and "Bug will occur" or "Can't reproduce"
"Can't reproduce"
>>> isinstance(simplejson.loads('"foo"'), unicode) and "Bug will occur" or "Can't reproduce"
"Can't reproduce"
>>>
>>> # System does not have speedup extension!
>>> import simplejson
>>> simplejson.decoder.c_scanstring is None and "Bug will occur" or "Can't reproduce"
'Bug will occur'
>>> isinstance(simplejson.loads('"foo"'), unicode) and "Bug will occur" or "Can't reproduce"
'Bug will occur'
>>>
The fix will ensure that OpenERP allows passing binary/image data in serialized form using unicode objects.
After further investigation the reason why this bug was hard to reproduce consistently is because it depends on how the 'simplejson' Python module was installed, and in particular whether its "speedups" C extension is available (but *not* on the version).
This also means it has nothing to do with the version of Python or psycopg2, even though trying to upgrade those may indirectly solve the issue if you happen to reinstall a different version of simplejson in the process.
The speedup-enabled version of simplejson will deserialize pure ASCII strings as plain str objects, whereas the pure Python implementation will always produce unicode objects regardless of the string contents.
The OpenERP framework was not ready to receive unicode strings for serialized binary/image fields, so it fails on any system where simplejson does not have the C extension installed.
You can check easily whether it is the case:
>>> # System has the speedup extension! decoder. c_scanstring is None and "Bug will occur" or "Can't reproduce" simplejson. loads(' "foo"') , unicode) and "Bug will occur" or "Can't reproduce"
>>> import simplejson
>>> simplejson.
"Can't reproduce"
>>> isinstance(
"Can't reproduce"
>>>
>>> # System does not have speedup extension! decoder. c_scanstring is None and "Bug will occur" or "Can't reproduce" simplejson. loads(' "foo"') , unicode) and "Bug will occur" or "Can't reproduce"
>>> import simplejson
>>> simplejson.
'Bug will occur'
>>> isinstance(
'Bug will occur'
>>>
The fix will ensure that OpenERP allows passing binary/image data in serialized form using unicode objects.