Bench migrate fails

Current Versions:
ERPNext: v14.20.3 (version-14)
Frappe Framework: v14.31.0 (version-14)
Frappe HR: v15.0.0-dev (develop)
India Compliance: v14.5.2 (version-14)
Payments: v0.0.1 (develop)

Bench migrate fails when running the patch

erpnext.patches.v13_0.convert_qi_parameter_to_link_field

While updating from v13 to v14, I got around this by running

bench migrate --skip-failing

Full trace back is shown below:

Traceback with variables (most recent call last):
File “/usr/lib/python3.10/runpy.py”, line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
mod_name = ‘frappe.utils.bench_helper’
alter_argv = True
mod_spec = ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f3a91577490>, origin=‘/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’)
code = <code object at 0x7f3a8f2b6550, file “/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 1>
main_globals = {‘name’: ‘main’, ‘doc’: None, ‘package’: ‘frappe.utils’, ‘loader’: <_frozen_importlib_external.SourceFileLoader object at 0x7f3a91577490>, ‘spec’: ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f3a91577490>, origin=‘/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’), ‘annotations’: {}, ‘builtins’: <module ‘builtins’ (built-in)>, ‘file’: ‘/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’, ‘cached’: ‘/home/milsign/frappe-bench/apps/frappe/frappe/utils/pycache/bench_helper.cpython-310.pyc’, ‘importlib’: <module ‘importlib’ from ‘/usr/lib/python3.10/importlib/init.py’>, ‘json’: <module ‘json’ from ‘/usr/lib/python3.10/json/init.py’>, ‘os’: <module ‘os’ from ‘/usr/lib/python3.10/os.py’>, ‘traceback’: <module ‘traceback’ from ‘/usr/lib/python3.10/traceback.py’>, ‘warnings’: <module ‘warnings’ from ‘/usr/lib/python3.10/warnings.py’>, ‘click’:…
File “/usr/lib/python3.10/runpy.py”, line 86, in _run_code
exec(code, run_globals)
code = <code object at 0x7f3a8f2b6550, file “/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 1>
run_globals = {‘name’: ‘main’, ‘doc’: None, ‘package’: ‘frappe.utils’, ‘loader’: <_frozen_importlib_external.SourceFileLoader object at 0x7f3a91577490>, ‘spec’: ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f3a91577490>, origin=‘/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’), ‘annotations’: {}, ‘builtins’: <module ‘builtins’ (built-in)>, ‘file’: ‘/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’, ‘cached’: ‘/home/milsign/frappe-bench/apps/frappe/frappe/utils/pycache/bench_helper.cpython-310.pyc’, ‘importlib’: <module ‘importlib’ from ‘/usr/lib/python3.10/importlib/init.py’>, ‘json’: <module ‘json’ from ‘/usr/lib/python3.10/json/init.py’>, ‘os’: <module ‘os’ from ‘/usr/lib/python3.10/os.py’>, ‘traceback’: <module ‘traceback’ from ‘/usr/lib/python3.10/traceback.py’>, ‘warnings’: <module ‘warnings’ from ‘/usr/lib/python3.10/warnings.py’>, ‘click’:…
init_globals = None
mod_name = ‘main
mod_spec = ModuleSpec(name=‘frappe.utils.bench_helper’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f3a91577490>, origin=‘/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’)
pkg_name = ‘frappe.utils’
script_name = None
loader = <_frozen_importlib_external.SourceFileLoader object at 0x7f3a91577490>
fname = ‘/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py’
cached = ‘/home/milsign/frappe-bench/apps/frappe/frappe/utils/pycache/bench_helper.cpython-310.pyc’
File “/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 109, in
main()
…skipped… 25 vars
File “/home/milsign/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 18, in main
click.Group(commands=commands)(prog_name=“bench”)
commands = {‘frappe’: , ‘get-frappe-commands’: , ‘get-frappe-help’: }
File “/home/milsign/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 829, in call
return self.main(*args, **kwargs)
self =
args = ()
kwargs = {‘prog_name’: ‘bench’}
File “/home/milsign/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 782, in main
rv = self.invoke(ctx)
self =
args = [‘frappe’, ‘migrate’]
prog_name = ‘bench’
complete_var = None
standalone_mode = True
extra = {}
ctx = <click.core.Context object at 0x7f3a9042fd90>
File “/home/milsign/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
_process_result = <function MultiCommand.invoke.._process_result at 0x7f3a8f2ba8c0>
args = [‘migrate’]
cmd_name = ‘frappe’
cmd =
sub_ctx = <click.core.Context object at 0x7f3a8f2a5b40>
ctx = <click.core.Context object at 0x7f3a9042fd90>
self =
File “/home/milsign/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
_process_result = <function MultiCommand.invoke.._process_result at 0x7f3a8f16c940>
args = []
cmd_name = ‘migrate’
cmd =
sub_ctx = <click.core.Context object at 0x7f3a8f353040>
ctx = <click.core.Context object at 0x7f3a8f2a5b40>
self =
File “/home/milsign/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
self =
ctx = <click.core.Context object at 0x7f3a8f353040>
File “/home/milsign/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 610, in invoke
return callback(*args, **kwargs)
args = ()
kwargs = {‘skip_failing’: False, ‘skip_search_index’: False}
self = <click.core.Context object at 0x7f3a8f353040>
callback = <function migrate at 0x7f3a8f31ce50>
ctx = <click.core.Context object at 0x7f3a8f353040>
File “/home/milsign/frappe-bench/env/lib/python3.10/site-packages/click/decorators.py”, line 21, in new_func
return f(get_current_context(), *args, **kwargs)
args = ()
kwargs = {‘skip_failing’: False, ‘skip_search_index’: False}
f = <function migrate at 0x7f3a8f31c310>
File “/home/milsign/frappe-bench/apps/frappe/frappe/commands/init.py”, line 29, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
ctx = <click.core.Context object at 0x7f3a8f353040>
args = ()
kwargs = {‘skip_failing’: False, ‘skip_search_index’: False}
profile = False
f = <function migrate at 0x7f3a8f31c280>
File “/home/milsign/frappe-bench/apps/frappe/frappe/commands/site.py”, line 557, in migrate
SiteMigration(
context = {‘sites’: [‘milsignerp.com’], ‘force’: False, ‘verbose’: False, ‘profile’: False}
skip_failing = False
skip_search_index = False
activate_by_import = <module ‘traceback_with_variables.activate_by_import’ from ‘/home/milsign/frappe-bench/env/lib/python3.10/site-packages/traceback_with_variables/activate_by_import.py’>
SiteMigration = <class ‘frappe.migrate.SiteMigration’>
site = ‘milsignerp.com
File “/home/milsign/frappe-bench/apps/frappe/frappe/migrate.py”, line 175, in run
self.run_schema_updates()
self = <frappe.migrate.SiteMigration object at 0x7f3a8f353340>
site = ‘milsignerp.com
File “/home/milsign/frappe-bench/apps/frappe/frappe/migrate.py”, line 41, in wrapper
ret = method(*args, **kwargs)
args = (<frappe.migrate.SiteMigration object at 0x7f3a8f353340>,)
kwargs = {}
method = <function SiteMigration.run_schema_updates at 0x7f3a875d1ea0>
File “/home/milsign/frappe-bench/apps/frappe/frappe/migrate.py”, line 110, in run_schema_updates
frappe.modules.patch_handler.run_all(
self = <frappe.migrate.SiteMigration object at 0x7f3a8f353340>
File “/home/milsign/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 75, in run_all
run_patch(patch)
patch_type = <PatchType.pre_model_sync: ‘pre_model_sync’>
executed = {‘erpnext.patches.v10_0.allow_operators_in_supplier_scorecard’, ‘erpnext.patches.v7_2.arrear_leave_encashment_as_salary_component’, ‘erpnext.patches.v8_9.set_default_customer_group’, ‘frappe.patches.v13_0.set_path_for_homepage_in_web_page_view’, ‘erpnext.patches.v13_0.set_app_name’, ‘frappe.patches.v12_0.remove_example_email_thread_notify’, ‘erpnext.patches.v11_0.refactor_naming_series’, ‘erpnext.patches.v12_0.add_gst_category_in_delivery_note’, ‘erpnext.patches.v13_0.rename_non_profit_fields’, ‘execute:frappe.delete_doc(“Print Format”, “SalesInvoice”)’, ‘frappe.patches.v12_0.move_email_and_phone_to_child_table’, ‘erpnext.patches.v12_0.move_bank_account_swift_number_to_bank’, ‘frappe.patches.v11_0.set_allow_self_approval_in_workflow’, ‘india_compliance.patches.v14.set_default_for_audit_trail_notification’, ‘erpnext.patches.v13_0.update_sane_transfer_against’, ‘execute:frappe.delete_doc(“Page”, “stock-ledger”)’, ‘erpnext.patches.v13_0.setting_custom_roles_for_some_regional_reports’, "ex…
run_patch = <function run_all..run_patch at 0x7f3a872b6d40>
patches = [‘frappe.patches.v12_0.remove_deprecated_fields_from_doctype #3’, ‘execute:frappe.utils.global_search.setup_global_search_table()’, “execute:frappe.reload_doc(‘core’, ‘doctype’, ‘doctype_action’, force=True) #2019-09-23”, “execute:frappe.reload_doc(‘core’, ‘doctype’, ‘doctype_link’, force=True) #2020-10-17”, “execute:frappe.reload_doc(‘core’, ‘doctype’, ‘doctype_state’, force=True) #2021-12-15”, “execute:frappe.reload_doc(‘core’, ‘doctype’, ‘doctype’, force=True) #2017-09-22”, “execute:frappe.reload_doc(‘core’, ‘doctype’, ‘docfield’, force=True) #2018-02-20”, ‘frappe.patches.v11_0.drop_column_apply_user_permissions’, “execute:frappe.reload_doc(‘core’, ‘doctype’, ‘custom_docperm’)”, “execute:frappe.reload_doc(‘core’, ‘doctype’, ‘docperm’) #2018-05-29”, “execute:frappe.reload_doc(‘core’, ‘doctype’, ‘comment’)”, “execute:frappe.reload_doc(‘core’, ‘doctype’, ‘document_naming_rule’, force=True)”, “execute:frappe.reload_doc(‘core’, ‘doctype’, ‘module_def’) #2020-08-28”, "execute:frappe.reloa…
patch = ‘erpnext.patches.v13_0.convert_qi_parameter_to_link_field’
skip_failing = False
File “/home/milsign/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 62, in run_patch
if not run_single(patchmodule=patch):
patch = ‘erpnext.patches.v13_0.convert_qi_parameter_to_link_field’
skip_failing = False
File “/home/milsign/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 150, in run_single
return execute_patch(patchmodule, method, methodargs)
patchmodule = ‘erpnext.patches.v13_0.convert_qi_parameter_to_link_field’
method = None
methodargs = None
force = False
conf =
File “/home/milsign/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 186, in execute_patch
_patch()
patchmodule = ‘erpnext.patches.v13_0.convert_qi_parameter_to_link_field’
method = None
methodargs = None
has_patch_file = True
patch = ‘erpnext.patches.v13_0.convert_qi_parameter_to_link_field.execute’
docstring = ‘’
_patch = <function execute at 0x7f3a872b6680>
start_time = 1681274995.0184326
File “/home/milsign/frappe-bench/apps/erpnext/erpnext/patches/v13_0/convert_qi_parameter_to_link_field.py”, line 23, in execute
frappe.get_doc(
reading_params = [‘30.2 mm’, ‘14.3mm’, ‘52mm’, ‘75 mm’, ‘48 mm’, ‘15.0 mm’, ‘69.5 mm’, ‘320 mm’, ‘29 mm’, ‘Dia 11’, ‘Dia 8’, ‘333mm’, ‘38mm’, ‘22mm’, ‘268mm’, ‘R 13’, ‘50mm’, ‘44mm’, ‘31mm’, ‘R 1 mm’, ‘30mm’, ‘65mm’, ‘345mm’, ‘268 mm’, ‘Hole dia 13mm’, ‘Hole dia 2mm’, ‘75mm’, ‘74mm’, ‘185 mm’, ‘R5 mm’, ‘R8 mm’, ‘215 mm’, ‘220 mm’, ‘182.7 mm’, ‘R3.5 mm’, ‘88 mm’, ‘36 mm’, ‘165 mm’, ‘345 mm’, ‘71 mm’, ‘91 mm’, ‘14.7 mm’, ‘203 mm’, ‘14.8 mm’, ‘3.42 mm’, ‘Dia 13.5’, ‘128.4 mm’, ‘12.6 mm’, ‘Dia 24’, ‘395 mm’, ‘17.6 mm’, ‘3.5 mm’, ‘12mm’, ‘245 mm’, ‘376 mm’, ‘R 5.0 mm’, ‘60 mm’, ‘284.2 mm’, ‘150mm’, ‘8 mm’, ‘85 mm’, ‘20.5 mm’, ‘63 mm’, ‘150 mm’, ‘140 mm’, ‘R 2.5’, ‘90 mm’, ‘93 mm’, ‘R 2.5 mm’, ‘25 mm’, ‘7 mm’, ‘80 mm’, ‘200 mm’, ‘55.2 mm’, ‘92 mm’, ‘84 mm’, ‘R 3.5 mm’, ‘64 mm’, ‘31 mm’, ‘32.1 mm’, ‘46 mm’, ‘410 mm’, ‘225 mm’, ‘170 mm’, ‘R2.0 mm’, ‘440 mm’, ‘70 mm’, ‘59 mm’, ‘47 mm’, ‘13mm’, ‘5mm’, ‘45mm’, ’ 8mm’, ‘440mm’, ‘284.2mm’, ‘427mm’, ‘20.3 mm’, ‘190 mm’, ‘104.5 mm’, ‘19 mm’, ‘58 mm’, ‘100 mm’, ‘28 mm…
template_params = []
params = [‘84 mm’, ‘52mm’, ‘15.5 mm’, ‘74mm’, ‘220.0 mm’, ‘0.5 mm’, ‘8.5 mm’, ‘28.0 mm’, ‘3.42 mm’, ‘R 70.0 mm’, ‘162.56 mm’, ‘14.7 mm’, ‘8 mm’, ‘95 mm’, ‘2.5 mm’, ‘38mm’, ‘150 mm’, ‘17.0 mm’, ‘29.0 mm’, ‘8’, ‘60.0 mm’, ‘89 mm’, ’ 26mm’, ‘R 2.0 mm’, ‘75 mm’, ‘31mm’, ‘21.5 mm’, ‘57.0 mm’, ‘138.0 mm’, ‘1.0’, ‘LASER MACHINING’, ‘225 mm’, ‘26 mm’, ‘32.1 mm’, ‘R 2.0’, ‘240 mm’, ‘19.5 mm’, ‘91 mm’, ‘190.0 mm’, ‘165 mm’, ’ 10mm’, ‘3.2 mm’, ‘31.0 mm’, ‘17.5 mm’, ‘14.3mm’, ’ 13mm’, ‘78 mm’, ‘120.0 mm’, ‘Hole dia 2mm’, ‘25 mm’, ‘1.5 mm’, ‘13 mm’, ‘52.5 mm’, ‘182.88 mm’, ‘14.0 mm’, ‘9 mm’, ‘185 mm’, ‘5 mm’, ‘440 mm’, ‘63 mm’, ‘21.0 mm’, ‘0.51 mm’, ‘203.1 mm’, ‘114mm’, ‘48.0 mm’, ‘3mm’, ‘70.0 mm’, ‘104.5 mm’, ‘R8 mm’, ‘192 mm’, ‘22 mm’, ‘5.5 mm’, ‘22mm’, ‘R 2.5 mm’, ‘24 mm’, ‘105mm’, ‘78.0 mm’, ‘Dia 11’, ‘69.5 mm’, ‘30.2 mm’, ‘22.0 mm’, ‘7.0 mm’, ‘150mm’, ‘4.8 mm’, ‘215.0 mm’, ‘215 mm’, ‘20mm’, ‘6.4 mm’, ‘81.0 mm’, ’ 8mm’, ‘19.0 mm’, ‘15.5’, ‘432 mm’, ‘2.2 mm’, ‘114.0 mm’, ‘3.0 mm’, ‘2.9 mm’, ‘2.0 mm’, ‘23…
parameter = ’ 26mm’
File “/home/milsign/frappe-bench/apps/frappe/frappe/model/document.py”, line 270, in insert
self.db_insert(ignore_if_duplicate=ignore_if_duplicate)
self = <QualityInspectionParameter: 26mm>
ignore_permissions = True
ignore_links = None
ignore_if_duplicate = False
ignore_mandatory = None
set_name = None
set_child_names = True
File “/home/milsign/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 529, in db_insert
raise frappe.DuplicateEntryError(self.doctype, self.name, e)
self = <QualityInspectionParameter: 26mm>
ignore_if_duplicate = False
conflict_handler = ‘’
d = {‘name’: ‘26mm’, ‘owner’: ‘Administrator’, ‘creation’: ‘2023-04-12 10:19:55.274256’, ‘modified’: ‘2023-04-12 10:19:55.274256’, ‘modified_by’: ‘Administrator’, ‘docstatus’: 0, ‘idx’: 0, ‘parameter’: ‘26mm’, ‘parameter_group’: None, ‘description’: ’ 26mm’}
columns = [‘name’, ‘owner’, ‘creation’, ‘modified’, ‘modified_by’, ‘docstatus’, ‘idx’, ‘parameter’, ‘parameter_group’, ‘description’]
frappe.exceptions.DuplicateEntryError: (‘Quality Inspection Parameter’, ‘26mm’, IntegrityError(1062, “Duplicate entry ‘26mm’ for key ‘PRIMARY’”))

We have a lot of old inspection reports made in v12 where quality inspection parameters are repeated.

Did you update from v12 → v14?
If so, you are likely to experience patching issues. It is safer to update v12->v13…and the v13->v14

Migrated from v12 to v13 and then v13 to v14.
The above problem was solved by exporting all the inspection reports to csv. Then, all the inspection reports were deleted and ran bench update. Afterwards all the reports were restored by using data import.

1 Like

Thank you for sharing your solution with the community!

1 Like