[6.1] Saving an image fails with "TypeError: can't escape non-string object" when simplejson does not have C speedup extension installed

Bug #899794 reported by ka
92
This bug affects 12 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Medium
OpenERP's Framework R&D

Bug Description

from a virtual ubuntu 10.04 server installing OpenERP from trunk:
OpenERP-server rev: 3848
OpenERP-addons rev: 5861
OpenERP-web rev: 1596
using pip for installing essentially all software except python-ldap, postgresql.

0) Go to http://<virtualserver>:8069
Create a new database without demo data
This should automatically log you in as Admin with a screen to install modules

1) Click "SETTINGS"
2) Click "Set Company Header and Footer"
3) Click folder icon to add new logo
4) Click "Save"

Result is:
OpenERP Server Error

Client Traceback (most recent call last):
  File "/opt/openerp/openerp-web/addons/web/common/http.py", line 154, in dispatch
    response["result"] = method(controller, self, **self.params)
  File "/opt/openerp/openerp-web/addons/web/controllers/main.py", line 772, in save
    r = m.write([id], data, req.session.eval_context(req.context))
  File "/opt/openerp/openerp-web/addons/web/common/openerplib/main.py", line 429, in proxy
    *args)
  File "/opt/openerp/openerp-web/addons/web/common/openerplib/main.py", line 306, in proxy
    result = self.connector.send(self.service_name, method, *args)
  File "/opt/openerp/openerp-web/addons/web/common/openerplib/main.py", line 276, in send
    raise fault

Server Traceback (most recent call last):
  File "/opt/openerp/openerp-web/addons/web/common/openerplib/main.py", line 257, in send
    result = openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/opt/openerp/openerp-server/openerp/netsvc.py", line 325, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp/openerp-server/openerp/service/web_services.py", line 580, in dispatch
    res = fn(db, uid, *params)
  File "/opt/openerp/openerp-server/openerp/osv/osv.py", line 120, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/opt/openerp/openerp-server/openerp/osv/osv.py", line 172, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/opt/openerp/openerp-server/openerp/osv/osv.py", line 163, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/openerp/openerp-server/openerp/addons/base/res/res_company.py", line 240, in write
    return super(res_company, self).write(cr, *args, **argv)
  File "/opt/openerp/openerp-server/openerp/osv/orm.py", line 3854, in write
    'where id IN %s', upd1 + [sub_ids])
  File "/opt/openerp/openerp-server/openerp/sql_db.py", line 153, in wrapper
    return f(self, *args, **kwargs)
  File "/opt/openerp/openerp-server/openerp/sql_db.py", line 215, in execute
    res = self._obj.execute(query, params)
TypeError: can't escape non-string object

Tags: 6.1 openerp

Related branches

affects: openerp-web → openerp-server
affects: openerp-server → openobject-server
Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
claude dunnigan (claudedunnigan) wrote :

same setup, almost same sitituation

when trying to add new child company and clicking save, i get

Client Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/addons/web/common/http.py", line 154, in dispatch
    response["result"] = method(controller, self, **self.params)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/addons/web/controllers/main.py", line 766, in create
    r = m.create(data, req.session.eval_context(req.context))
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/addons/web/common/openerplib/main.py", line 429, in proxy
    *args)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/addons/web/common/openerplib/main.py", line 306, in proxy
    result = self.connector.send(self.service_name, method, *args)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/addons/web/common/openerplib/main.py", line 276, in send
    raise fault

Server Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/addons/web/common/openerplib/main.py", line 257, in send
    result = openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/netsvc.py", line 325, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/service/web_services.py", line 580, in dispatch
    res = fn(db, uid, *params)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/osv/osv.py", line 120, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/osv/osv.py", line 172, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/osv/osv.py", line 163, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/addons/base/res/res_company.py", line 234, in create
    company_id = super(res_company, self).create(cr, uid, vals, context=context)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/osv/orm.py", line 4116, in create
    cr.execute('insert into "'+self._table+'" (id'+upd0+") values ("+str(id_new)+upd1+')', tuple(upd2))
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/sql_db.py", line 153, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/openerp-6.1beta-py2.6.egg/openerp/sql_db.py", line 215, in execute
    res = self._obj.execute(query, params)
TypeError: can't escape non-string object

Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello claude dunnigan, kandresen

Yes..you are absolutely right. The problem will be reproduced only on pc's where you have psycopg2 version less then 2.4.1
there was an upstream bug in psycopg2 http://initd.org/psycopg/docs/faq.html which has been fixed in psycopg2 2.4.1 version

Regards,

Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

needs to move to web as GTK works perfectly I am not sure but it seems the web is not sending the binary data as expected.

@xavier: can you please confirm !

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello,

We have tried to reproduce this issue on many different setups, and it is very hard to reproduce (hence difficult to assign a proper importance to the bug). It seems to be dependent on the version of psycopg2 (and perhaps Python and PostgreSQL too), but we have not been able to pinpoint the actual component that causes this yet.
I don't think this is related to the psycopg FAQ entry mentioned in comment #2, because it is specific to PostgreSQL 9.0 and the only case where we could detect the problem was with PostgreSQL 8.4.

We are continuing to investigate, but we need as much information as possible to diagnose this, such as:
- what version of Python, PostgreSQL, Psycopg2 are you using?
- can you reproduce this problem on other machines? (using which versions?)
- could you try upgrading psycopg2 to the latest version if this is not what you are using?

Thanks for any information you could provide!

Changed in openobject-server:
importance: Medium → Undecided
status: Confirmed → Incomplete
Revision history for this message
Kenneth Andresen (kandresen) wrote :

I am currently using psycopg2 v 2.0.13 so I guess that might be it. Trying to upgrade using
pip install --upgrade psycopg2 or easy_install --upgrade psycopg2 does however fail after downloading psycopg2 2.4.3 with an error: "pg_config executable not found"

I will look into it when I get some time.

Revision history for this message
Kenneth Andresen (kandresen) wrote :

I have found psycopg2 requires not only libpq-dev but gcc as well... That is ok in development, but normally NOT acceptable at the time of deployment. I believe is a huge mistake to require GCC to be required on a web-server. I will likely not be testing this until an acceptable workaround exist.

anyway, in case it should be a problem in another place, the command "pip freeze" give the following result:
Babel==0.9.6
Mako==0.2.5
PIL==1.1.7
PyChart==1.39
PyWebDAV==0.9.3
PyYAML==3.09
Werkzeug==0.8.1
ZSI==2.1-a1
bzr-etckeeper==0.0.0
distribute==0.6.10
gdata.py==1.2.4
ghostscript==0.4.1
lxml==2.2.4
matplotlib==0.99.1.1
numpy==1.3.0
psycopg2==2.0.13
pycrypto==2.0.1
pycurl==7.19.0
pycurl-wrapper==1.0-7-g19d27bb
pydot==1.0.2
pyparsing==1.5.2
python-dateutil==2.0
python-openid==2.2.5
pythondialog==2.7
pytz==2011n
reportlab==2.4
simplejson==2.2.1
turnkey-pylib==0.3-30-gb86db51
vobject==0.8.1c
wsgiref==0.1.2

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote : Re: [Bug 899794] Re: [6.1] cannot upload company logo

On 12/16/2011 02:48 AM, Kenneth Andresen wrote:
> I have found psycopg2 requires not only libpq-dev but gcc as well...
> That is ok in development, but normally NOT acceptable at the time of
> deployment. I believe is a huge mistake to require GCC to be required on
> a web-server. I will likely not be testing this until an acceptable
> workaround exist.

You might be overreacting here ;-)

The error with missing "pg_config" during upgrade/install shows that
there is no precompiled binary available for your platform, so
pip/easy_install have to download the source version and compile it on
the spot. psycopg2 is not a pure Python lib, it contains native C code
that depends on the platform, in order to talk to the postgres native
libs. Hence the compilation step when installing from source.
This is the only reason why postgres' development tools and gcc are
neeeded on the machine. They won't be used after psycopg2 is installed,
you could even remove them.

Now if you don't like that on a production machine, why don't you
install a precompiled binary version of psycopg2 instead? Depending on
your platform, it might be readily available in your distribution
packages. On a recent Ubuntu for example:

 $ sudo apt-cache show python-psycopg2 | grep Version
 Version: 2.4.2-1
 $ # ^^ this means I can install a binary version with apt-get

Another option is to install it with easy_install on a development
machine (with the same architecture as the prod machine) and then
transfer the resulting Python egg (easy_install will build one and
install it on the dev machine) to the prod machine.
You can install an egg directly with:
 $ sudo easy_install <egg_file>

Note that none of the above is OpenERP-specific, it's merely Python
packaging/installation stuff.

Cheers,

Revision history for this message
Kenneth Andresen (kandresen) wrote : Re: [6.1] cannot upload company logo

I did find the package python-psycopg2-2.4.2-1 only for Ubuntu 11.10 which have only slightly more than one year of support left. I cannot find any option for Ubuntu 10.04 LTS, and 12.04 LTS wont be released until April. Redhat 6 does not have the package neither, only Fedora, but that's again not for servers. Redhat 7 will likely not be released until at least 2013. Redhat ES 6 - 6.2 uses python-psycopg2-2.0.13 just like Ubuntu 10.04 LTS!

For development machines and so on there is no problem using unofficial packages and so on, but I believe we are intending to sell OpenERP to enterprise. I have had a support contract with Redhat before, and I do know that if you rebuild for example php you also loose official support for Apache - you are on your own! That is typically unacceptable options unless you are doing your own in-house support - where you typically have system administrators, not developers - and even then most system administrators prefer having someone to call when things happen!

I am not saying you cannot run any unofficial packages what so ever neither, but requiring rebuild of packages such as PHP or Python, or installation of GCC are usually off limits.

In other words - we are pulling OpenERP further away from the groups we are trying to approach.

I did try to install the python-psycopg-2.4.2-1 package just in case but that package requires python-2.7.1, and likely a slew of other updates, and I believe that to resolve that would mean to go thorough dependency hell.

Revision history for this message
Ian Beardslee (ibeardslee) wrote :

I get a similar problem trying to install a new module.

Ubuntu Lucid 10.04 doesn't have the correct version of Python (needed by libpq-dev and the more recent version of psycopg2). I'm about to update my testing VM to Ubuntu Precise 12.04 to see how that deals with it all.

Revision history for this message
Ian Beardslee (ibeardslee) wrote :

Without having to stuff around much at all, I have OpenERP 6.1 working with Python 2.7.2 on Ubuntu Precise 12.04 LTS .. and not getting that "TypeError: can't escape non-string object" error anymore. Although I wouldn't recommend doing that for a production system just yet!

summary: - [6.1] cannot upload company logo
+ [6.1] random requests fail with "can't escape non-string object"
summary: - [6.1] random requests fail with "can't escape non-string object"
+ [6.1] random requests fail with "TypeError: can't escape non-string
+ object"
Revision history for this message
Dieter (dieterb) wrote : Re: [6.1] random requests fail with "TypeError: can't escape non-string object"

Hi all,

When I perform the actions as described in the original post, I also got this error. I post the stacktrace below.

My environment:

Windows XP SP3
Postgres 8.3
OpenERP 6.1rc1-20120112-173907 (the installer I downloaded from the site)

In that version of OpenERP, I believe all python libs are packaged, so I don't use any specific version of psycopg

Revision history for this message
Dieter (dieterb) wrote :

Stacktrace:
Client Traceback (most recent call last):
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\openerp\addons\web\common\http.py", line 176, in dispatch
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\openerp\addons\web\controllers\main.py", line 816, in save
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\openerp\addons\web\common\openerplib\main.py", line 250, in proxy
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\openerp\addons\web\common\openerplib\main.py", line 117, in proxy
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\openerp\addons\web\common\http.py", line 579, in send

Server Traceback (most recent call last):
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\openerp\addons\web\common\http.py", line 560, in send
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\.\openerp\netsvc.py", line 325, in dispatch_rpc
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\.\openerp\service\web_services.py", line 580, in dispatch
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\.\openerp\osv\osv.py", line 166, in execute_kw
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\.\openerp\osv\osv.py", line 120, in wrapper
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\.\openerp\osv\osv.py", line 175, in execute
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\.\openerp\osv\osv.py", line 163, in execute_cr
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\openerp\addons\base\res\res_company.py", line 241, in write
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\.\openerp\osv\orm.py", line 3883, in write
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\.\openerp\sql_db.py", line 153, in wrapper
  File "C:\Program Files\OpenERP 6.1rc1-20120112-173907\server\.\openerp\sql_db.py", line 215, in execute
TypeError: can't escape non-string object

Revision history for this message
fenshuajiang (ojenerp) wrote :

I have updated the psycopy to psycopg2-2.4.4 ,but the problem remains.
Ubuntu 10.04 LTS
Postgres 8.4

Revision history for this message
Kenneth Andresen (kandresen) wrote :

I myself have moved to Debian 6.0.4 and installed OpenERP 6.1 from nightly build of February 16th 2012.
This problem described for Ubuntu 10.04 is not present when using Debian 6.0.4.
Debian 7 have feature freeze in June, and will likely use some more time before being released, so Debian 6 should be supported until the middle of 2013 somewhere.

Still, I think it is really bad OpenERP 6.1 is not backwards compatible with Ubuntu 10.04 LTS and Redhat ES 6.

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote : Re: [Bug 899794] Re: [6.1] random requests fail with "TypeError: can't escape non-string object"

On 02/16/2012 05:09 AM, Kenneth Andresen wrote:
> I myself have moved to Debian 6.0.4 and installed OpenERP 6.1 from nightly
> build of February 16th 2012. This problem described for Ubuntu 10.04 is not
> present when using Debian 6.0.4. Debian 7 have feature freeze in June, and
> will likely use some more time before being released, so Debian 6 should be
> supported until the middle of 2013 somewhere.
>
> Still, I think it is really bad OpenERP 6.1 is not backwards compatible
> with Ubuntu 10.04 LTS and Redhat ES 6.

Thank you for the feedback. As I think was made very clear in earlier comments
(e.g. comment #4), this bug has not yet been identified, hence the status
Incomplete. There is absolutely no move from OpenERP to stop supporting
whatever version of Linux or Python you're using, nor to ask for recompiling
your own version, so there is no point complaining about that.

It's very simple: as we can *not* reproduce this error consistently, we cannot
even know if there is anything we can do within OpenERP to work around it. As
far as we know, OpenERP 6.1 is not different from 6.0 when it comes to writing
to the database using psycopg2.

If you have a hint or patch to help work around the problem in OpenERP, we'll
be glad to review it and merge it.

Thanks,

Revision history for this message
Kenneth Andresen (kandresen) wrote : Re: [6.1] random requests fail with "TypeError: can't escape non-string object"

Oliver, you yourself claimed OpenERP 6.1 require a version of Psycopg2 that does not exist for Ubuntu 10.04.

If you can point me to the PPA for Ubuntu 10.04 that has a psycopg2 newer than 2.0.13, then this is not an issue.

If you are saying OpenERP 6.1 actually is working for some on Ubuntu 10.04 using psycopg2==2.0.13 then I can agree with you - but you seemed to claim that version did not work.

The official PPA list is here: https://launchpad.net/ubuntu/+source/psycopg2

Assuming 2.0.13 does not work with OpenERP 6.1, then how can you claim Ubuntu 10.04 is supported without requiring any compilation? To me Ubuntu 10.04 is not supported until the OpenERP 6.1 code either work with Psycopg2 2.0.13 as well as newer versions, or that Psycopg2 version exist for 10.04 that works with OpenERP. As I see it, OpenERP does not currently work with Ubuntu 10.04. I would love it if you can prove me wrong by providing installation instructions for Ubuntu 10.04 that result in OpenERP 6.1 working without any manual compilation of code.

Revision history for this message
tamnil (saito-x) wrote :

i got the error while inserting a product.

reported in bug: Bug #934312

linked with this bug.

Revision history for this message
tamnil (saito-x) wrote :

as described in bug: Bug #919982 by ruy medeiros

"
Hi,

I'm using Ubuntu 10.04 with Postgresql 8.4.10, psycopg 2.4.4, Openerp 6.1 RC1 and got struck with this error too. All forms with binary fields in the model were causing this error.

After fiddling in google, I found this bug report http://psycopg.lighthouseapp.com/projects/62710/tickets/51-typeerror-cant-escape-unicode-to-binary-writing-unicode-into-bytea which made me suspicious that openerp was trying to convert to binary the form field as unicode, thus psycopg threw the error.

I have no idea if this is the right fix, but what I did to sort it out was to cast the form field content as a string before the binary conversion by psycopg in osv/fields.py the end result is:

_symbol_f = lambda symb: symb and Binary(str(symb)) or None

on line 296 of osv/fields.py

Again, I have no idea whatsoever if this is the right fix, I'm sure this is where the problem is caused though.

Best regards,"

it was worked fine.!
but in my version it´s in line 332.
i don´t know how it affect the other fields.

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote : Re: [Bug 899794] Re: [6.1] random requests fail with "TypeError: can't escape non-string object"

On 02/20/2012 12:19 PM, tamnil wrote:
> as described in bug: Bug #919982 by ruy medeiros
> _symbol_f = lambda symb: symb and Binary(str(symb)) or None
<SNIP>
>
> on line 296 of osv/fields.py
>
> Again, I have no idea whatsoever if this is the right fix, I'm sure this
> is where the problem is caused though.

Tanmil, Rui, thanks for the very insightful details. I think we are coming
close to the root of the problem. There may indeed be some changes in OpenERP
6.1 that can cause certain binary blobs to be transferred as unicode strings
instead of 8-bit strings.

Would any of you guys mind sharing the image or binary that causes the issue to
occur for you? This could in fact be related to the actual binary content of
the file, and thus could be image-specific.

Based on this we should be able to provide a proper fix (the workaround of Rui
is not bad, but a little bit more of analysis is required)

Thanks!

summary: - [6.1] random requests fail with "TypeError: can't escape non-string
- object"
+ [6.1] Setting an image or binary field may sometimes fail with
+ "TypeError: can't escape non-string object"
Changed in openobject-server:
importance: Undecided → Medium
milestone: none → 6.1
status: Incomplete → Confirmed
Revision history for this message
tamnil (saito-x) wrote : RES: [Bug 899794] Re: [6.1] Setting an image or binary field may sometimes fail with "TypeError: can't escape non-string object"
Download full text (5.0 KiB)

Here ´s one of images that i had trouble to upload to the server.

-----Mensagem original-----
De: <email address hidden> [mailto:<email address hidden>] Em nome de Olivier Dony (OpenERP)
Enviada em: segunda-feira, 20 de fevereiro de 2012 10:08
Para: <email address hidden>
Assunto: [Bug 899794] Re: [6.1] Setting an image or binary field may sometimes fail with "TypeError: can't escape non-string object"

On 02/20/2012 12:19 PM, tamnil wrote:
> as described in bug: Bug #919982 by ruy medeiros
> _symbol_f = lambda symb: symb and Binary(str(symb)) or None
<SNIP>
>
> on line 296 of osv/fields.py
>
> Again, I have no idea whatsoever if this is the right fix, I'm sure this
> is where the problem is caused though.

Tanmil, Rui, thanks for the very insightful details. I think we are coming
close to the root of the problem. There may indeed be some changes in OpenERP
6.1 that can cause certain binary blobs to be transferred as unicode strings
instead of 8-bit strings.

Would any of you guys mind sharing the image or binary that causes the issue to
occur for you? This could in fact be related to the actual binary content of
the file, and thus could be image-specific.

Based on this we should be able to provide a proper fix (the workaround of Rui
is not bad, but a little bit more of analysis is required)

Thanks!

** Summary changed:

- [6.1] random requests fail with "TypeError: can't escape non-string object"
+ [6.1] Setting an image or binary field may sometimes fail with "TypeError: can't escape non-string object"

** Changed in: openobject-server
   Importance: Undecided => Medium

** Changed in: openobject-server
       Status: Incomplete => Confirmed

** Changed in: openobject-server
    Milestone: None => 6.1

--
You received this bug notification because you are subscribed to a
duplicate bug report (934312).
https://bugs.launchpad.net/bugs/899794

Title:
  [6.1] Setting an image or binary field may sometimes fail with
  "TypeError: can't escape non-string object"

Status in OpenERP Server:
  Confirmed

Bug description:
  from a virtual ubuntu 10.04 server installing OpenERP from trunk:
  OpenERP-server rev: 3848
  OpenERP-addons rev: 5861
  OpenERP-web rev: 1596
  using pip for installing essentially all software except python-ldap, postgresql.

  0) Go to http://<virtualserver>:8069
  Create a new database without demo data
  This should automatically log you in as Admin with a screen to install modules

  1) Click "SETTINGS"
  2) Click "Set Company Header and Footer"
  3) Click folder icon to add new logo
  4) Click "Save"

  Result is:
  OpenERP Server Error

  Client Traceback (most recent call last):
    File "/opt/openerp/openerp-web/addons/web/common/http.py", line 154, in dispatch
      response["result"] = method(controller, self, **self.params)
    File "/opt/openerp/openerp-web/addons/web/controllers/main.py", line 772, in save
      r = m.write([id], data, req.session.eval_context(req.context))
    File "/opt/openerp/openerp-web/addons/web/common/openerplib/main.py", line 429, in proxy
      *args)
    File "/opt/openerp/openerp-web/addons/web/common/openerplib/main.py", line 306, in proxy
      result = self.connector.send(sel...

Read more...

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote : Re: [6.1] Setting an image or binary field may sometimes fail with "TypeError: can't escape non-string object"

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.

summary: - [6.1] Setting an image or binary field may sometimes fail with
- "TypeError: can't escape non-string object"
+ [6.1] Saving an image fails with "TypeError: can't escape non-string
+ object" when simplejson does not have C speedup extension installed
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello,

The fix for this issue landed in the 6.1 branch at revision 4072 rev-id: <email address hidden>.

Thanks a lot to all those who provided feedback and helped in the analysis and resolution of this bug (especially Rui Barreiros who provided the final clue and patch in comment #8 of bug 919982)

Changed in openobject-server:
status: Confirmed → Fix Released
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Some minor remarks about this bug:

1. The version of psycopg2 is irrelevant for the occurrence of the bug, however it will cause a minor difference in the error message: older versions (e.g. 2.0) will raise a "TypeError: can't escape non-string object" while more recent version (e.g. 2.4) will raise a "TypeError: can't escape unicode to binary".

2. This bug did not occur in 6.0 because it is caused by the JSON (de)serialization of OpenERP binary values, and the JSON protocol was only introduced in OpenERP 6.1 - nothing else changed between 6.0 and 6.1 in the handling of binaries or the way we use psycopg2.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.