upgrade-util
upgrade-util copied to clipboard
[FIX] util/fields: ensure path update for ir_exports_line
Issue: When exporting data using the existing export template, a traceback error occurs.
Traceback (most recent call last):
File "/home/odoo/src/odoo/17.0/odoo/http.py", line 1783, in _serve_db
return service_model.retrying(self._serve_ir_http, self.env)
File "/home/odoo/src/odoo/17.0/odoo/service/model.py", line 133, in retrying
result = func()
File "/home/odoo/src/odoo/17.0/odoo/http.py", line 1810, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "/home/odoo/src/odoo/17.0/odoo/http.py", line 2014, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "/home/odoo/src/odoo/17.0/odoo/addons/base/models/ir_http.py", line 222, in _dispatch
result = endpoint(**request.params)
File "/home/odoo/src/odoo/17.0/odoo/http.py", line 759, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/home/odoo/src/odoo/17.0/addons/web/controllers/export.py", line 369, in namelist
fields_data = self.fields_info(
File "/home/odoo/src/odoo/17.0/addons/web/controllers/export.py", line 418, in fields_info
fields[base]['relation'], base, fields[base]['string'],
KeyError: 'move_lines'
Cause: When a field is renamed, the path in ir_exports_line
is not updated if it contains .ids
. This happens because the resolve_model_fields_path fails to retrieve the field record from ir_model_fields
where the field name is .id
here (because such field doesn't exists), which leads to failing this condition because of the difference in length of old and new path
Some output from shell for better understanding here :
Genereted new_path
In [20]: new_path = [ ...: new_field_name ...: if field.field_name == old_field_name and field.field_model in only_models ...: else field.field_name ...: for field in resolve_model_fields_path(cr, 'stock.picking', ['move_lines','.id']) ...: ] In [21]: new_path Out[21]: ['move_ids']
Expected new_path
In [22]: new_path = [ ...: new_field_name ...: if field.field_name == old_field_name and field.field_model in only_models ...: else field.field_name ...: for field in resolve_model_fields_path(cr, 'stock.picking', ['move_lines','id']) ...: ] In [23]: new_path Out[23]: ['move_ids', 'id']
Original:
test_15.0=> select * from ir_exports_line ;
id | name | export_id | create_uid | create_date | write_uid | write_date
----+------------------------------------+-----------+------------+----------------------------+-----------+----------------------------
20 | move_lines/.id | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
21 | move_lines/show_details_visible | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
22 | move_lines/company_id | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
23 | move_lines/product_uom_category_id | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
(4 rows)
Before Fix:
test_15.0_17.0=> select * from ir_exports_line ;
id | name | export_id | create_uid | create_date | write_uid | write_date
----+----------------------------------+-----------+------------+----------------------------+-----------+----------------------------
20 | move_lines/.id | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
21 | move_ids/show_details_visible | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
22 | move_ids/company_id | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
23 | move_ids/product_uom_category_id | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
(4 rows)
After Fix:
test_15.0_17.0=> select * from ir_exports_line ;
id | name | export_id | create_uid | create_date | write_uid | write_date
----+----------------------------------+-----------+------------+----------------------------+-----------+----------------------------
20 | move_ids/.id | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
21 | move_ids/show_details_visible | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
22 | move_ids/company_id | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
23 | move_ids/product_uom_category_id | 6 | 2 | 2024-09-06 09:25:01.707598 | 2 | 2024-09-06 09:25:01.707598
(4 rows)