Issue 10413

Title
Setting a translatable Char field with an SQL expression mess with its translation
Priority
bug
Status
resolved
Nosy list
ced, nicoe, reviewbot, roundup-bot
Assigned to
ced
Keywords
review

Created on 2021-05-12.11:39:35 by nicoe, last changed 11 months ago by roundup-bot.

Messages

New changeset 7041a6ec28a9 by Cédric Krier in branch 'default':
Use and test the proper type for quantity and total_quantity in inventory counting
https://hg.tryton.org/tryton-env/rev/7041a6ec28a9
New changeset 2400885ad5ea by Cédric Krier in branch 'default':
Use and test the proper type for quantity and total_quantity in inventory counting
https://hg.tryton.org/modules/stock/rev/2400885ad5ea
New changeset 876eb6131622 by Cédric Krier in branch 'default':
Prevent assign SQL value to record instances
https://hg.tryton.org/tryton-env/rev/876eb6131622
New changeset 51719a6696d5 by Cédric Krier in branch 'default':
Prevent assign SQL value to record instances
https://hg.tryton.org/trytond/rev/51719a6696d5
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-10-30 16:44:44roundup-botsetmessages: + msg71431
2021-10-30 16:44:38roundup-botsetmessages: + msg71430
2021-10-28 09:01:02roundup-botsetmessages: + msg71341
2021-10-28 09:00:59roundup-botsetmessages: + msg71340
nosy: + roundup-bot
status: testing -> resolved
2021-10-23 12:07:12reviewbotsetmessages: + msg71259
nosy: + reviewbot
2021-10-23 12:01:26cedsetkeyword: + review
reviews: 379441002
status: in-progress -> testing
2021-10-23 11:08:20cedsetassignedto: ced
status: chatting -> in-progress
type: crash
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)