Issue 10413

Setting a translatable Char field with an SQL expression mess with its translation
Nosy list
ced, nicoe
Assigned to

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


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/", line 203, in wrapper
    result = func(*args, **kwargs)
  File "/home/nicoe/projets/tryton/tryton-env/TrimCharField-[issue7914](issue7914)/trytond/trytond/tests/", 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/", line 159, in wrapper
    return func(cls, *args, **kwargs)
  File "/home/nicoe/projets/tryton/tryton-env/TrimCharField-[issue7914](issue7914)/trytond/trytond/model/", line 662, in create
    Translation.set_ids(name, 'model', Transaction().language,
  File "/home/nicoe/projets/tryton/tryton-env/TrimCharField-[issue7914](issue7914)/trytond/trytond/ir/", line 513, in set_ids
    translation.value = value
  File "/home/nicoe/projets/tryton/tryton-env/TrimCharField-[issue7914](issue7914)/trytond/trytond/model/fields/", 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.

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)