Add-Remove-Add application

I’ve run into an issue when adding an App, then removing it, and later trying to re-add it.
Here are the steps I’ve taken:

  1. Create a new App.

bench new-app mynewapp

  1. Added this new App to a site.

bench --site mysite1 install-app mynewapp

  1. Verify the installation

bench --site mysite1 list-apps

  1. Next, remove the App we just installed.

bench --site mysite1 remove-from-installed-apps mynewapp

  1. Verify the removal (this works)

bench --site mysite1 list-apps

  1. Add the App back again to the site.

bench --site mysite1 install-app mynewapp

And here’s the error:
frappe.exceptions.DuplicateEntryError: (u’Module Def’, u’Mynewapp’, IntegrityError(1062, “Duplicate entry ‘Mynewapp’ for key ‘PRIMARY’”))

It appears Bench is trying to add another row to MariaDB table “tabModule Def”, however the row was previously added during the first App installation.

Suggestion for Fix

  1. Removing the App should also remove the row from MariaDB.
  2. When adding an App, Bench should check if it’s already in the “tabModule Def” table.

To uninstall try:

bench --site site name uninstall-app appname


Great suggestion. I’ve confirmed that command works successfully. It also removes the row from MariaDB, as expected.

The only catch: your site has to be actively online and running. The command fails with errors if your site is offline. In a perfect world, we’d have error-handling in Bench to state this cleanly (i.e. "You cannot execute this command while your site is offline; please start your site and try again.")

Follow-up question:

If “uninstall-app” is the correct command to use. Then what is the purpose of “remove-from-installed-apps” command? It’s listed under “bench --help”, which is how I found it. If it has no purpose, should it be removed from Bench?