Skip to content

Commit e7d1a8a

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 d261a1f commit e7d1a8a

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")
@@ -39,7 +41,7 @@ def add_snippet_names(cr, table, column, snippets, select_query):
3941
_logger.info("Add snippet names on %s.%s", table, column)
4042
cr.execute(select_query)
4143

42-
it = util.log_progress(cr.fetchall(), _logger, qualifier="rows", size=cr.rowcount, log_hundred_percent=True)
44+
it = log_progress(cr.fetchall(), _logger, qualifier="rows", size=cr.rowcount, log_hundred_percent=True)
4345

4446
def quote(ident):
4547
return quote_ident(ident, cr._cnx)
@@ -107,11 +109,11 @@ def html_fields(cr):
107109
"""
108110
)
109111
for model, columns in cr.fetchall():
110-
table = util.table_of_model(cr, model)
111-
if not util.table_exists(cr, table):
112+
table = table_of_model(cr, model)
113+
if not table_exists(cr, table):
112114
# an SQL VIEW
113115
continue
114-
existing_columns = [column for column in columns if util.column_exists(cr, table, column)]
116+
existing_columns = [column for column in columns if column_exists(cr, table, column)]
115117
if existing_columns:
116118
yield table, existing_columns
117119

@@ -171,7 +173,7 @@ def make_pickleable_callback(callback):
171173
"""
172174
callback_filepath = inspect.getfile(callback)
173175
name = f"_upgrade_{uuid.uuid4().hex}"
174-
mod = sys.modules[name] = util.import_script(callback_filepath, name=name)
176+
mod = sys.modules[name] = import_script(callback_filepath, name=name)
175177
try:
176178
return getattr(mod, callback.__name__)
177179
except AttributeError:
@@ -260,7 +262,7 @@ def convert_html_columns(cr, table, columns, converter_callback, where_column="I
260262

261263
assert "id" not in columns
262264

263-
converters = {column: "->>'en_US'" if util.column_type(cr, table, column) == "jsonb" else "" for column in columns}
265+
converters = {column: "->>'en_US'" if column_type(cr, table, column) == "jsonb" else "" for column in columns}
264266
select = ", ".join(f'"{column}"' for column in columns)
265267
where = " OR ".join(f'"{column}"{converters[column]} {where_column}' for column in columns)
266268

@@ -280,9 +282,9 @@ def convert_html_columns(cr, table, columns, converter_callback, where_column="I
280282

281283
matched_count = 0
282284
converted_count = 0
283-
with ProcessPoolExecutor(max_workers=util.get_max_workers()) as executor:
285+
with ProcessPoolExecutor(max_workers=get_max_workers()) as executor:
284286
convert = Convertor(converters, converter_callback)
285-
for query in util.log_progress(split_queries, logger=_logger, qualifier=f"{table} updates"):
287+
for query in log_progress(split_queries, logger=_logger, qualifier=f"{table} updates"):
286288
cr.execute(query)
287289
for data in executor.map(convert, cr.fetchall()):
288290
matched_count += 1

0 commit comments

Comments
 (0)