Tryton - Issues

 

Issue6128

Title psycopg2cffi can't ascii encode character sql_contrain
Priority bug Status resolved
Superseder Nosy List ced, resteve, reviewbot, roundup-bot
Type crash Components trytond
Assigned To ced Keywords review
Reviews 31831002,43971002
View: 31831002, 43971002

Created on 2016-12-20.10:22:40 by resteve, last changed by roundup-bot.

Messages
New changeset 301c452ec3b6 by Cédric Krier in branch '4.6':
Use unicode instead of str for DatabaseIntegrityError
http://hg.tryton.org/trytond/rev/301c452ec3b6

New changeset 5a5b16418ff0 by Cédric Krier in branch '4.4':
Use unicode instead of str for DatabaseIntegrityError
http://hg.tryton.org/trytond/rev/5a5b16418ff0

New changeset d29d113fc22d by Cédric Krier in branch '4.2':
Use unicode instead of str for DatabaseIntegrityError
http://hg.tryton.org/trytond/rev/d29d113fc22d

New changeset 03754c5de377 by Cédric Krier in branch '4.0':
Use unicode instead of str for DatabaseIntegrityError
http://hg.tryton.org/trytond/rev/03754c5de377

New changeset 56284277f27c by Cédric Krier in branch '3.8':
Use unicode instead of str for DatabaseIntegrityError
http://hg.tryton.org/trytond/rev/56284277f27c
New changeset 01a600ff73c5 by Cédric Krier in branch 'default':
Use unicode instead of str for DatabaseIntegrityError
http://hg.tryton.org/trytond/rev/01a600ff73c5
review43971002 updated at https://codereview.tryton.org/43971002/#ps1
msg38293 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2018-02-10.18:37:29
Indeed as explained in [1], the __str__ on Exception is in Python if the message is not ASCII. So there is no clean solution, except that in Python3 the problem does not exist as strings are always unicode. So I propose to always use unicode instead of str as the database encoding should be UTF-8.

So here is review43971002

[1] https://stackoverflow.com/questions/1272138/baseexception-message-deprecated-in-python-2-6
msg31014 (view) Author: [hidden] (resteve) Date: 2016-12-28.10:46:23
I think both commits was released in 2.7.5 (31 October 2016) and doesn't fix.

I open new issue at chtd/psycopg2cffi:

https://github.com/chtd/psycopg2cffi/issues/75
msg31010 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2016-12-28.10:26:16
Or maybe it is https://github.com/chtd/psycopg2cffi/issues/56
msg31009 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2016-12-28.10:24:17
It seems it has been fixed by https://github.com/chtd/psycopg2cffi/pull/72
msg31000 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2016-12-28.00:09:56
No this is not a good solution for two reasons:
- the problem is in psycopg2cffi so it should be fixed there
- nothing said that psycopg2cffi does not have the bug with unicode method

So the bug must be reported upstream.
msg30998 (view) Author: [hidden] (resteve) Date: 2016-12-27.23:32:30
Other idea is convert exception (1) to unicode:

            except DatabaseIntegrityError, exception:
                exception = unicode(exception).encode('utf-8')
                transaction = Transaction()

(1) https://bitbucket.org/tryton/trytond/src/bcea32cb1aaef7c4b345e01a76b49d2c237bb7c1/trytond/model/modelsql.py?at=default&fileviewer=file-view-default#modelsql.py-557

PyPy 5.6.0 + py2.7 + psycopg2cffi 2.7.5
msg30976 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2016-12-26.19:36:36
Re-open it because tests fail on python3
https://drone.tryton.org/trypod.tryton.org/tryton/trytond/default/bd4fb1ec9ebb33eeb03eee4b801a443e884197b5

I think it is indeed probably a bug in psycopg2cffi. It should not fail when calling str.
New changeset bcea32cb1aae by C?dric Krier in branch 'default':
Backed out changeset bd4fb1ec9ebb
http://hg.tryton.org/trytond/rev/bcea32cb1aae
New changeset bd4fb1ec9ebb by C?dric Krier in branch 'default':
Avoid to convert IntegrityError into string
http://hg.tryton.org/trytond/rev/bd4fb1ec9ebb
review31831002 updated at https://codereview.tryton.org/31831002/#ps1
msg30902 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2016-12-22.00:10:43
Should be fixed with review31831002
msg30833 (view) Author: [hidden] (resteve) Date: 2016-12-20.10:22:39
With psycopg2cffi installed (v2.7.5), can't 'ascii' codec when check sql_constrain (and _sql_error_messages?).

The traceback:

12071 140328623490816 [2016-12-20 06:38:33,119] ERROR trytond.protocols.dispatcher <class 'trytond.pool.account.account'>.create(*([{u'kind': u'receivable', u'childs': [], u'name': u'ddd', u'different_party_reconcile': False, u'company': 1, u'taxes': [], u'note': u'', u'active': True, u'code': u'', u'deferral': True, u'general_ledger_balance': False, u'second_currency': None, u'party_required': False, u'type': 1, u'reconcile': False}], {u'date_format': u'%x', u'language': None, u'groups': [12, 1, 11, 6, 18, 14, 8, 3, 4, 5, 7, 21, 2, 17, 19, 13, 10, 15, 9, 16, 22, 20], u'employee': None, u'language_direction': u'ltr', u'company': 1, u'company.rec_name': u'cc', '_check_access': True}), **{}) from admin@185.73.168.17//xxx/
Traceback (most recent call last):
  File "/home/xxx/tryton/trytond/trytond/protocols/dispatcher.py", line 160, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/home/xxx/tryton/trytond/trytond/modules/account_parent_code/account.py", line 98, in create
    accounts = super(Account, cls).create(vlist)
  File "/home/xxx/tryton/trytond/trytond/model/modelsql.py", line 558, in create
    exception, values, transaction=transaction)
  File "/home/xxx/tryton/trytond/trytond/model/modelsql.py", line 307, in __raise_integrity_error
    if name in str(exception):
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 31: ordinal not in range(128)

I check this line [1] and the type is:

<class 'psycopg2cffi._impl.exceptions.IntegrityError'>

Detected in 4.2

[1] https://bitbucket.org/tryton/trytond/src/dd969de519a84a6b3062701a190da1e4ffb3c974/trytond/model/modelsql.py?at=4.2&fileviewer=file-view-default#modelsql.py-306
History
Date User Action Args
2018-02-25 01:05:49roundup-botsetmessages: + msg38602
2018-02-19 19:09:10roundup-botsetstatus: testing -> resolved
messages: + msg38476
2018-02-10 18:55:31reviewbotsetmessages: + msg38294
2018-02-10 18:37:29cedsetstatus: deferred -> testing
reviews: 31831002 -> 31831002,43971002
messages: + msg38293
keyword: + review
assignedto: ced
2017-03-01 19:25:43cedsetkeyword: - review
2016-12-28 10:46:23restevesetmessages: + msg31014
2016-12-28 10:26:16cedsetmessages: + msg31010
2016-12-28 10:24:17cedsetmessages: + msg31009
2016-12-28 00:09:56cedsetstatus: chatting -> deferred
messages: + msg31000
2016-12-27 23:32:30restevesetmessages: + msg30998

Showing 10 items. Show all history (warning: this could be VERY long)