Unique constraint for a selection field

We (@Thedevilcoder and me) are stuck at a very trivial issue. We are trying to create a selection field and getting this error (with traceback)-

Traceback (most recent call last):
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/protocols/dispatcher.py", line 176, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/wizard/wizard.py", line 287, in execute
    return wizard._execute(state_name)
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/wizard/wizard.py", line 318, in _execute
    result = self._execute(transition())
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/ir/module.py", line 582, in transition_upgrade
    pool.init(update=update, lang=lang)
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/pool.py", line 160, in init
    lang=lang, activatedeps=activatedeps)
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/modules/__init__.py", line 423, in load_modules
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/modules/__init__.py", line 388, in _load_modules
    load_module_graph(graph, pool, update, lang)
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/modules/__init__.py", line 216, in load_module_graph
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/model/modelsql.py", line 201, in __register__
    super(ModelSQL, cls).__register__(module_name)
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/model/model.py", line 123, in __register__
    Translation.register_fields(cls, module_name)
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/ir/translation.py", line 240, in register_fields
    insert_selection(field, trans_name)
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/ir/translation.py", line 231, in insert_selection
    '', module_name, False, -1]]))
  File "/home/prakhar/workspace/tryton/tryton50/src/trytond/trytond/backend/postgresql/database.py", line 65, in execute
    cursor.execute(self, sql, args)
psycopg2.IntegrityError: duplicate key value violates unique constraint "ir_translation_translation_md5_uniq"
DETAIL:  Key (name, res_id, lang, type, src_md5, module)=(gdm.workflow,state, -1, en, selection, ea4788705e6873b424c65e91c2846b19, gdm_cohort) already exists.

The code is very simple and we have reduced the model to only this content -

from trytond.model import (ModelSQL, ModelView, fields, Workflow)
from trytond.pyson import Eval

__all__ = ['GdmWorkflow',

class GdmWorkflow(Workflow, ModelSQL, ModelView):

    __name__ = 'gdm.workflow'

    state = fields.Selection(
            ('draft', 'Draft'),
            ('f_to_administer', 'Forwarded to Administer'),
            ('cancel_deo', 'Cancel'),
            ('f_to_reviewer', 'Forwarded to Reviewer'),
            ('cancel_administer', 'Cancel'),
            ('f_b_to_administer', 'Sent to administer for further administration'),
            ('finalise_form', 'Form Freezed'),
        ], 'Status')

We know that we are missing a minor detail here but are not able to figure out.

Do you have an .po file with the translations? It seems you have defined a translation twice.

Or if you updated a database from 5.0 series, you are missing some of the migration queries. See the 5.0 to 5.2 migration page.

@edbo No, there is no translation file.

We are still working on 5.0. (Trytond Version is 5.0.18)

Does it happen on a clean new database?
I think you have former translation registered in your database. You may run clean translation wizards before introduce the new changes.

@ced This is happening on a clean database. I have asked all my team mates to run this code on their respective systems on a clean database. If we all face the same issue then I will share the code with community.

The issue is solved. I guess you can’t repeat the label in the selection field. So here, cancel_deo and cancel_admin … both have “Cancel” as the label and this is why the duplicate translation error was coming up.

Thanks for the help !!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.