Exclude constraint Postgres SyntaxError

trytond-admin -c /app/trytond.conf -d umbrella --all

While running the above command, I get the following error.

Traceback (most recent call last):
File “/usr/local/bin/trytond-admin”, line 33, in
admin.run(options)
File “/usr/local/lib/python3.12/site-packages/trytond/admin.py”, line 59, in run
pool.init(update=options.update, lang=list(lang),
File “/usr/local/lib/python3.12/site-packages/trytond/pool.py”, line 144, in init
restart = not load_modules(
^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/trytond/modules/init.py”, line 402, in load_modules
_load_modules(update)
File “/usr/local/lib/python3.12/site-packages/trytond/modules/init.py”, line 372, in _load_modules
load_module_graph(graph, pool, update, lang, indexes)
File “/usr/local/lib/python3.12/site-packages/trytond/modules/init.py”, line 200, in load_module_graph
cls.register(module)
File “/usr/local/lib/python3.12/site-packages/trytond/ir/model.py”, line 1001, in register
super().register(module_name)
File “/usr/local/lib/python3.12/site-packages/trytond/model/fields/fmany2one.py”, line 34, in register
super().register(module)
File “/usr/local/lib/python3.12/site-packages/trytond/model/modelsql.py”, line 543, in register
table.add_constraint(ident, constraint)
File “/usr/local/lib/python3.12/site-packages/trytond/backend/postgresql/table.py”, line 513, in add_constraint
cursor.execute(
File “/usr/local/lib/python3.12/site-packages/trytond/backend/postgresql/database.py”, line 76, in execute
cursor.execute(self, sql, args)
psycopg2.errors.SyntaxError: syntax error at or near ““active””
LINE 1: …USING BTREE (“name” WITH =, “model” WITH =) WHERE “active” =…

After some debugging, I found the line causing the problem in trytond/ir/model.py line 1013.

    @classmethod
    def __setup__(cls):

        super(ModelButton, cls).__setup__()

        cls.__access__.add('model_ref')

        t = cls.__table__()

        cls._sql_constraints += [

            ('name_model_exclude',

                Exclude(t, (t.name, Equal), (t.model, Equal),

                    where=(t.active == Literal(True))),

                'ir.msg_button_name_unique'),

            ]

        cls._order.insert(0, ('model', 'ASC'))

This issue was discovered recently; it had been working correctly before.
I am using trytond==7.4.0.

Thanks in advance for your help.

7.4 series is no more supported 20 January 2026 and so it did not receive the backport for Missing explicit parentheses around WHERE clause of EXCLUDE constraint (#14449) · Issues · Tryton / Tryton · GitLab.

Do I need to upgrade my project to fix this issue?

In general, it is always better to stay on a supported series (that’s why we have the LTS for 5 years).

Now a quick fix is to downgrade to python-sql < 1.8.

And for your case as you do not seem to eager about new features, I would recommend to upgrade to the future LTS 8.0 series (in a month) like that you are setup for 5 years.

1 Like

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