Silent "ascii encode exception" when trying to raise an exception with special characters

Bug #509572 reported by Borja López Soilán (NeoPolus)
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
KDE OpenObject Client
New
Undecided
Unassigned

Bug Description

When Koo receives an exception from the server with special (non-ascii) characters, it just fails silently to decode the exception, and the user is never notified that something went wrong.

How to reproduce it (tested on revno 1267):

Set the user language to English, then go to "Administration -> Low Level Objects -> Actions -> Window Actions", select the first item. Try to change the "Object" field to "somethingthatdoesnotexist" and save the record:
     - An exception appears ("ValidateError - Error ocurred while validating the field(s) res_model,src_model: Invalid model name in the action definition.") as it should.

Set the user language to Spanish, then go to "Administración -> Objetos de bajo nive l-> Acciones -> Acciones de ventana", select the first item. Try to change the "Objeto" field to "somethingthatdoesnotexist" and save the record:
    - No exception appears (the user might think that everything went all right... but he is wrong).
    - The document was not saved (on the status bar it displays "Document modified")
    - The next stacktrace is logged on the console:

-----------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/Koo/Dialogs/KooMainWindow.py", line 719, in callChildView
    res = wid.handlers[action]()
  File "/usr/local/lib/python2.6/dist-packages/Koo/Dialogs/FormWidget.py", line 347, in save
    id = self.screen.save()
  File "/usr/local/lib/python2.6/dist-packages/Koo/Screen/Screen.py", line 599, in save
    id = self.currentRecord().save(reload=True)
  File "/usr/local/lib/python2.6/dist-packages/Koo/Model/Record.py", line 248, in save
    if not self.rpc.write([self.id], value, context):
  File "/usr/local/lib/python2.6/dist-packages/Koo/Rpc/Rpc.py", line 579, in __call__
    return session.execute('/object', 'execute', self.object, self.func, *args)
  File "/usr/local/lib/python2.6/dist-packages/Koo/Rpc/Rpc.py", line 420, in execute
    return self.call(obj, method, *args)
  File "/usr/local/lib/python2.6/dist-packages/Koo/Rpc/Rpc.py", line 408, in call
    value = self.connection.call(obj, method, *args)
  File "/usr/local/lib/python2.6/dist-packages/Koo/Rpc/Rpc.py", line 187, in call
    result = s.myreceive()
  File "/usr/local/lib/python2.6/dist-packages/Koo/Rpc/tiny_socket.py", line 130, in myreceive
    raise Myexception(str(res[0]), str(res[1]))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 123: ordinal not in range(128)
-----------------------------

The exception not shown should have displayed "ValidateError - Ha ocurrido un error mientras se validaban los campo(s) res_model,src_model: Nombre de modelo inválido en la definición de la acción".
(Note: the exception is properly displayed on the GTK client)

description: updated
tags: added: ascii encode exception
Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

Some extra info using the debugger:

------------

ipdb> res[0]
Exception(u'warning -- ValidateError\n\nHa ocurrido un error mientras se validaban los campo(s) res_model,src_model: Nombre de modelo inv\xe1lido en la definici\xf3n de la acci\xf3n',)

ipdb> str(res[0])
*** UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 123: ordinal not in range(128)

ipdb> unicode(res[0])
u'warning -- ValidateError\n\nHa ocurrido un error mientras se validaban los campo(s) res_model,src_model: Nombre de modelo inv\xe1lido en la definici\xf3n de la acci\xf3n'

------------

Also, if I replace the "raise Myexception(str(res[0]), str(res[1]))" line in tiny_socket.py with the next code, then the exception is properly displayed:

    try:
        res_0 = str(res[0])
        res_1 = str(res[1])
    except UnicodeEncodeError:
        res_0 = unicode(res[0]).encode('utf-8')
        res_1 = unicode(res[1]).encode('utf-8')
    raise Myexception(res_0, res_1)

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

Other bug subscribers

Remote bug watches

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