New custom app breaks ERPNext

Following the documentation, I am trying to create and use a new app on the latest non-development version of frappe available, visible below:

$ bench version
erpnext 10.1.54
frappe 10.1.49

Running the following works as expected:

$ bench new-app bsb
INFO:bench.app:creating new app bsb
App Title (default: Test): bsb
App Description: bsb
App Publisher: bsb
App Email: bsb@bsb.com
App Icon (default 'octicon octicon-file-directory'): 
App Color (default 'grey'): 
App License (default 'MIT'): 
'bsb' created at /home/frappe/frappe-bench/apps/bsb
INFO:bench.app:installing bsb
INFO:bench.utils:./env/bin/pip install -q  -e ./apps/bsb --no-cache-dir

I now have a folder in ~/frappe-bench/apps called “bsb” set up exactly as I would expect.

Trying to install the app however does not work.

$ bench install-app bsb
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 64, in get_app_commands
app_command_module = importlib.import_module(app + '.commands')
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named bsb.commands
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/apps/frappe/frappe/commands/utils.py", line 447, in get_version
frappe.init('')
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 158, in init
setup_module_map()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 872, in setup_module_map
for module in get_module_list(app):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 746, in get_module_list
return get_file_items(os.path.join(os.path.dirname(get_module(app_name).__file__), "modules.txt"))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 704, in get_module
return importlib.import_module(modulename)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named bsb

At this point, all bench commands result in this same error message and the ERP site itself displays the following on all pages:

The only way to fix the issue that I have found is to remove “bsb” from ~/frappe-bench/sites/apps.txt, at which point ERPNext returns to normal but I cannot use bench execute on my python scripts. Can anybody help me figure out what’s going wrong with bench new-app?

Mention site name while installing app and see if it works or not

bench --site site1.local bsb

Exactly the same error @root13F :

Without “bsb” in ~/frappe-bench/sites/apps.txt:

$ bench --site site1.local install-app bsb
Could not find app "bsb"

With “bsb” in ~/frappe-bench/sites/apps.txt:

$ bench --site site1.local install-app bsb                                                                                                                                            
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 64, in get_app_commands
app_command_module = importlib.import_module(app + '.commands')
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named bsb.commands
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 165, in install_app
_install_app(app, verbose=context.verbose)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 109, in install_app
frappe.clear_cache()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 510, in clear_cache
frappe.sessions.clear_cache()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/sessions.py", line 47, in clear_cache
clear_global_cache()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/sessions.py", line 57, in clear_global_cache
frappe.setup_module_map()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 872, in setup_module_map
for module in get_module_list(app):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 746, in get_module_list
return get_file_items(os.path.join(os.path.dirname(get_module(app_name).__file__), "modules.txt"))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 704, in get_module
return importlib.import_module(modulename)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named bsb

I forgot to mention site1.local is a generic name, I expected you to enter your site name. You can find that name in currentsite.txt in Sites folder

$ cat sites/currentsite.txt 
site1.local

I have managed to get my custom app working. I switched to the development branch, and bench new-app, bench install-app and bench execute myapp.myfunction all work as expected. Current versions are the following:

$ bench version
fatal: Not a git repository (or any of the parent directories): .git
bsb 0.0.1
erpnext 10.1.54
frappe 12.x.x-develop

The “Not a git repository” doesn’t seem to be negatively affecting anything, so I don’t think it’s worrisome.

EDIT: I even reverted back to the master branch, and the app continued to function as expected. It seems specifically and only the “bench new-app” command is broken for the current stable branch.

1 Like