Error on uninstall-app frappe.exceptions.LinkExistsError: Cannot delete or cancel because Module Def is linked with Print Format

I was trying to install my custom app on my frappe site,
it failed with the following error:
root@rrpp-erp1:/home/frappe/frappe-bench# bench install-app fpo
Installing fpo…
Updating fpo : [========================================]
Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 162, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 79, in
main()
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 16, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/init.py”, line 24, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py”, line 152, in install_app
_install_app(app, verbose=context.verbose)
File “/home/frappe/frappe-bench/apps/frappe/frappe/installer.py”, line 134, in install_app
sync_from_app(name)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/doctype/desktop_icon/desktop_icon.py”, line 315, in sync_from_app
{‘module_name’: m[‘module_name’], ‘app’: app, ‘standard’: 1})
KeyError: u’module_name’

Then I tried to uninstall it, to retry, but the uninstall is also failing
root@rrpp-erp1:/home/frappe/frappe-bench# bench uninstall-app fpo
All doctypes (including custom), modules related to this app will be deleted. Are you sure you want to continue (y/n) ? y
Backing up…
removing DocType Farmer Quotation…
removing DocType Farmer Quotation Item…
removing DocType Farmer…
removing Page pop…
removing Module FPO…
Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 162, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 79, in
main()
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 16, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/init.py”, line 24, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py”, line 315, in uninstall
remove_app(app, dry_run, yes)
File “/home/frappe/frappe-bench/apps/frappe/frappe/installer.py”, line 203, in remove_app
frappe.delete_doc(“Module Def”, module_name)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 631, in delete_doc
ignore_permissions, flags)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py”, line 93, in delete_doc
check_if_doc_is_linked(doc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py”, line 180, in check_if_doc_is_linked
item.parent or item.name), frappe.LinkExistsError)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 309, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 302, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 275, in _raise_exception
raise raise_exception, encode(msg)
frappe.exceptions.LinkExistsError: Cannot delete or cancel because Module Def FPO is linked with Print Format Point of Purchase

the said print format is located here.

I saw a similar issue with web forms, Is there a workaround?

Manually deleting the row from db worked
delete from tabPrint Format where Module = ‘FPO’;

3 Likes