Skip to content

Commit cef8114

Browse files
committed
[FIX] util.snippets: replace odoo.upgrade.util import with relative
`util.snippets` imports util from `odoo.upgrade` namespace package and that makes it incompatible with odoo versions <= 13.0. Replaced the import with direct package-relative ones.
1 parent 0475cc5 commit cef8114

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/util/snippets.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
from psycopg2.extras import Json
1313

1414
from .exceptions import MigrationError
15-
from odoo.upgrade import util
15+
from .helpers import table_of_model
16+
from .misc import import_script, log_progress
17+
from .pg import column_exists, column_type, get_max_workers, table_exists
1618

1719
_logger = logging.getLogger(__name__)
1820
utf8_parser = html.HTMLParser(encoding="utf-8")
@@ -38,7 +40,7 @@ def add_snippet_names(cr, table, column, snippets, select_query):
3840
_logger.info("Add snippet names on %s.%s", table, column)
3941
cr.execute(select_query)
4042

41-
it = util.log_progress(cr.fetchall(), _logger, qualifier="rows", size=cr.rowcount, log_hundred_percent=True)
43+
it = log_progress(cr.fetchall(), _logger, qualifier="rows", size=cr.rowcount, log_hundred_percent=True)
4244

4345
def quote(ident):
4446
return quote_ident(ident, cr._cnx)
@@ -103,11 +105,11 @@ def html_fields(cr):
103105
"""
104106
)
105107
for model, columns in cr.fetchall():
106-
table = util.table_of_model(cr, model)
107-
if not util.table_exists(cr, table):
108+
table = table_of_model(cr, model)
109+
if not table_exists(cr, table):
108110
# an SQL VIEW
109111
continue
110-
existing_columns = [column for column in columns if util.column_exists(cr, table, column)]
112+
existing_columns = [column for column in columns if column_exists(cr, table, column)]
111113
if existing_columns:
112114
yield table, existing_columns
113115

@@ -169,7 +171,7 @@ def make_pickleable_callback(callback):
169171
"""
170172
callback_filepath = inspect.getfile(callback)
171173
name = f"_upgrade_{uuid.uuid4().hex}"
172-
mod = sys.modules[name] = util.import_script(callback_filepath, name=name)
174+
mod = sys.modules[name] = import_script(callback_filepath, name=name)
173175
try:
174176
return getattr(mod, callback.__name__)
175177
except AttributeError:
@@ -257,7 +259,7 @@ def convert_html_columns(cr, table, columns, converter_callback, where_column="I
257259
"""
258260
assert "id" not in columns
259261

260-
converters = {column: "->>'en_US'" if util.column_type(cr, table, column) == "jsonb" else "" for column in columns}
262+
converters = {column: "->>'en_US'" if column_type(cr, table, column) == "jsonb" else "" for column in columns}
261263
select = ", ".join(f'"{column}"' for column in columns)
262264
where = " OR ".join(f'"{column}"{converters[column]} {where_column}' for column in columns)
263265

@@ -277,9 +279,9 @@ def convert_html_columns(cr, table, columns, converter_callback, where_column="I
277279

278280
matched_count = 0
279281
converted_count = 0
280-
with ProcessPoolExecutor(max_workers=util.get_max_workers()) as executor:
282+
with ProcessPoolExecutor(max_workers=get_max_workers()) as executor:
281283
convert = Convertor(converters, converter_callback)
282-
for query in util.log_progress(split_queries, logger=_logger, qualifier=f"{table} updates"):
284+
for query in log_progress(split_queries, logger=_logger, qualifier=f"{table} updates"):
283285
cr.execute(query)
284286
for data in executor.map(convert, cr.fetchall()):
285287
matched_count += 1

0 commit comments

Comments
 (0)