Issue 10413

Title
Setting a translatable Char field with an SQL expression mess with its translation
Priority
bug
Status
chatting
Nosy list
ced, nicoe
Assigned to
Keywords

Created on 2021-05-12.11:39:35 by nicoe, last changed 2 months ago by ced.

Messages

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2021-07-02.23:46:35

Indeed the only way I found to support this is the .createand .write read back from the database the values that have just been inserted/updated. So they can be used for the translation.
But I think it is too much for this marginal use case. So I think the best option is to raise an error in ir.translation if the value is not a string.

Author: [hidden] (nicoe) Tryton committer
Date: 2021-05-12.11:39:34

Here is the traceback (it only happens with the patch I made for issue7914 because it overrides __set__ but the issue is there anyway):

Traceback (most recent call last):
  File "/home/nicoe/projets/tryton/tryton-env/TrimCharField-[issue7914](issue7914)/trytond/trytond/tests/test_tryton.py", line 203, in wrapper
    result = func(*args, **kwargs)
  File "/home/nicoe/projets/tryton/tryton-env/TrimCharField-[issue7914](issue7914)/trytond/trytond/tests/test_field_char.py", line 49, in test_create_with_sql_value
    char, = Char.create([{'char': Literal('Foo')}])
  File "/home/nicoe/projets/tryton/tryton-env/TrimCharField-[issue7914](issue7914)/trytond/trytond/model/modelsql.py", line 159, in wrapper
    return func(cls, *args, **kwargs)
  File "/home/nicoe/projets/tryton/tryton-env/TrimCharField-[issue7914](issue7914)/trytond/trytond/model/modelsql.py", line 662, in create
    Translation.set_ids(name, 'model', Transaction().language,
  File "/home/nicoe/projets/tryton/tryton-env/TrimCharField-[issue7914](issue7914)/trytond/trytond/ir/translation.py", line 513, in set_ids
    translation.value = value
  File "/home/nicoe/projets/tryton/tryton-env/TrimCharField-[issue7914](issue7914)/trytond/trytond/model/fields/char.py", line 66, in __set__
    value = value.strip()
AttributeError: 'Literal' object has no attribute 'strip'

As a consequence it will also set an Expression value in the _values dictionary of the translation instance.
I think we should raise an Error when doing this.

History
Date User Action Args
2021-07-02 23:46:35cedsetcomponent: + trytond
messages: + msg68529
nosy: + ced
status: unread -> chatting
2021-05-12 11:39:35nicoecreate

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