From 2af3624e7d6a04c39442d8abe5b29e2e25cff355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 11 Sep 2024 16:05:50 +0200 Subject: [PATCH] Support JSONB when migrating quality operations Since 33c7f6e19680 JSONB is used by default for MultiSelection. Closes #13500 --- modules/quality/quality.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/quality/quality.py b/modules/quality/quality.py index 052e1f927e..4557f458d4 100644 --- a/modules/quality/quality.py +++ b/modules/quality/quality.py @@ -207,6 +207,7 @@ class Control(DeactivableMixin, MatchMixin, ModelSQL, ModelView): def __register__(cls, module): table = cls.__table__() transaction = Transaction() + database = transaction.database cursor = transaction.connection.cursor() update = transaction.connection.cursor() @@ -221,13 +222,21 @@ class Control(DeactivableMixin, MatchMixin, ModelSQL, ModelView): 'stock.shipment.internal:do'), ('production:done', 'production:do'), ]: + try: + where = database.json_key_exists(table.operations, old) + except NotImplementedError: + where = table.operations.like(f'%{old}%') cursor.execute(*table.select( - table.id, table.operations, - where=table.operations.like(f'%{old}%'))) + table.id, table.operations, where=where)) for id_, operations in cursor: + if isinstance(operations, (list, tuple)): + value = cls.operations.sql_format( + [x.replace(old, new) for x in operations]) + else: + value = operations.replace(old, new) update.execute(*table.update( [table.operations], - operations.replace(old, new), + value, where=table.id == id_)) @classmethod