Skip to content

Commit

Permalink
[FIX] models.py: Don't commit after fetching a translation
Browse files Browse the repository at this point in the history
Purpose
=======

When trying the translate a sql_contraint message after an integrity error
we use the current cursor in a 'with', just to make a SELECT query.

That way, the cursor is commited at the end of the with statement, trying
to commit the inconsitent state of the cursor that was the reason of the
integrity error.

Just close the cursor, as we only fetch translations from the database.

closes odoo#36458

Signed-off-by: Yannick Tivisse (yti) <[email protected]>
  • Loading branch information
tivisse committed Sep 11, 2019
1 parent 5a032bb commit 1a0a437
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion odoo/service/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from contextlib import closing
from functools import wraps
import logging
from psycopg2 import IntegrityError, OperationalError, errorcodes
Expand Down Expand Up @@ -73,7 +74,7 @@ def tr(src, ttype):

# We open a *new* cursor here, one reason is that failed SQL
# queries (as in IntegrityError) will invalidate the current one.
with odoo.sql_db.db_connect(dbname).cursor() as cr:
with closing(odoo.sql_db.db_connect(dbname).cursor()) as cr:
if ttype == 'sql_constraint':
res = translate_sql_constraint(cr, key=key, lang=lang)
else:
Expand Down

0 comments on commit 1a0a437

Please sign in to comment.