Uninstall-app fails when app contains print formats

Hi all,

I have an issue with a custom app: when trying to run

bench uninstall-app ham

it fails with

frappe.exceptions.LinkExistsError: Cannot delete or cancel because Module Def <a href="#Form/Module Def/ham">ham</a> is linked with Print Format <a href="#Form/Print Format/cheese">cheese</a>

The custom app contains the mentioned print format (which should also be removed on uninstall). Obeserved in Frappe 10.0.15/ERPNext 10.0.14.

Full trace is

$ bench uninstall-app ham
(...)
removing Module ham...
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, 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 94, in<module>
main()
 File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, 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 330, in uninstall
    remove_app(app, dry_run, yes)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 212, in remove_app
    frappe.delete_doc("Module Def", module_name)
   File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 673, in delete_doc
ignore_permissions, flags, ignore_on_trash, ignore_missing)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py", line 87, in delete_doc
    check_if_doc_is_linked(doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py", line 202, in check_if_doc_is_linked
    raise_link_exists_exception(doc, linked_doctype, reference_docname)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/delete_doc.py", line 253, in raise_link_exists_exception
    .format(doc.doctype, doc_link, reference_doctype, reference_link, row), frappe.LinkExistsError)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 323, in throw
msgprint(msg, raise_exception=exc, title=title, indicator='red')
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 309, in msgprint
_raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 282, in _raise_exception
    raise raise_exception(encode(msg))
frappe.exceptions.LinkExistsError: Cannot delete or cancel because Module Def <a href="#Form/Module Def/ham">ham</a> is linked with Print Format <a href="#Form/Print Format/cheese">cheese</a>

Am I missing something, is there a hack to uninstall an app with print formats? I can manually remove them, but that seems painful… Any hints appreciated.

try this delete from tabPrint Format where Module = ‘ham’;
and then uninstall app

1 Like

Hi @vishdha,
thanks, this worked (I deleted the Print Formats from the UI Print Format List).

However, I believe this should be done by the bench in the function uninstall…

yeah, sounds good
Create issue on github

Issue created: