NameError: name 'module' is not defined

Good Afternoon!

I am working on a python script to import records from legacy software and am struggling to get it to execute. It’s located at
/bench/frappe-bench/apps/storeinfo/storeinfo/sales_importer/dbf_sales_import.py

I know I’m probably missing something obvious but any guidance/help would be really appreciated! I’ve tried a bunch of different “bench execute” commands and have gotten similar errors.

erpnext@host:/opt/bench/frappe-bench$ bench execute storeinfo.sales_importer.dbf_sales_import
Traceback (most recent call last):
  File "/opt/bench/frappe-bench/apps/frappe/frappe/commands/utils.py", line 239, in execute
    ret = frappe.get_attr(method)(*args, **kwargs)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/__init__.py", line 1437, in get_attr
    return getattr(get_module(modulename), methodname)
AttributeError: module 'storeinfo.sales_importer' has no attribute 'dbf_sales_import'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 110, in <module>
    main()
  File "/opt/bench/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 31, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/commands/utils.py", line 241, in execute
    ret = frappe.safe_eval(
  File "/opt/bench/frappe-bench/apps/frappe/frappe/__init__.py", line 2079, in safe_eval
    return eval(code, eval_globals, eval_locals)
  File "<string>", line 1, in <module>
NameError: name 'storeinfo' is not defined
erpnext@host:/opt/bench/frappe-bench$ bench execute storeinfo.sales_importer.dbf_sales_import
Traceback (most recent call last):
  File "/opt/bench/frappe-bench/apps/frappe/frappe/commands/utils.py", line 239, in execute
    ret = frappe.get_attr(method)(*args, **kwargs)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/__init__.py", line 1437, in get_attr
    return getattr(get_module(modulename), methodname)
AttributeError: module 'storeinfo.sales_importer' has no attribute 'dbf_sales_import'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 110, in <module>
    main()
  File "/opt/bench/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/bench/frappe-bench/env/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 31, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/opt/bench/frappe-bench/apps/frappe/frappe/commands/utils.py", line 241, in execute
    ret = frappe.safe_eval(
  File "/opt/bench/frappe-bench/apps/frappe/frappe/__init__.py", line 2079, in safe_eval
    return eval(code, eval_globals, eval_locals)
  File "<string>", line 1, in <module>
NameError: name 'storeinfo' is not defined


Thank you!!

1 Like

Try running bench update --reset after defining a new app. There might be a faster/shorter way to do this, as that goes through the works of updating, compiling, migrating, restarting, etc, but that’s been the more sure-fire way I’ve found to work around this error after defining a new app.

@PersistentDabbler are you sure it’s correct path of your function ?