Module import failed for Shift Type, the DocType you're trying to open might be deleted

Hello Everyone,

I’ve been encountering the following error during a system update on my self-hosted deployment. It seems to be related to the hrms application.

The error:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/utils.py", line 282, in load_doctype_module
    doctype_python_modules[key] = frappe.get_module(module_name)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1454, in get_module
    return importlib.import_module(modulename)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/frappe/frappe-bench/apps/hrms/hrms/hr/doctype/shift_type/shift_type.py", line 24, in <module>
    from erpnext.setup.doctype.holiday_list.holiday_list import is_half_holiday, is_holiday
ImportError: cannot import name 'is_half_holiday' from 'erpnext.setup.doctype.holiday_list.holiday_list' (/home/frappe/frappe-bench/apps/erpnext/erpnext/setup/doctype/holiday_list/holiday_list.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 114, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1442, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1363, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1830, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1830, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1226, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 794, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/decorators.py", line 34, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 683, in migrate
    SiteMigration(
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 193, in run
    self.run_schema_updates()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 54, in wrapper
    raise e
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 46, in wrapper
    ret = method(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 123, in run_schema_updates
    frappe.model.sync.sync_all()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py", line 44, in sync_all
    sync_for(app, force, reset_permissions=reset_permissions)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py", line 112, in sync_for
    import_file_by_path(
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 146, in import_file_by_path
    import_doc(
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 239, in import_doc
    doc.insert()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 334, in insert
    self.run_post_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1177, in run_post_save_methods
    self.run_method("on_update")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1011, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1371, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1353, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1008, in fn
    return method_object(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 549, in on_update
    self.run_module_method("on_doctype_update")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 647, in run_module_method
    module = load_doctype_module(self.name, self.module)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/utils.py", line 286, in load_doctype_module
    raise ImportError(msg) from e
ImportError: Module import failed for Shift Type, the DocType you're trying to open might be deleted.
Error: cannot import name 'is_half_holiday' from 'erpnext.setup.doctype.holiday_list.holiday_list' (/home/frappe/frappe-bench/apps/erpnext/erpnext/setup/doctype/holiday_list/holiday_list.py)

The Fix:

I think the should be just a temporary fix and the underlying issue should be addressed by the core team, as the “half a shift” feature seems important, even though we don’t currently use it in my organization. In order to update ERPNext, the way I go around this is a follows:

nano frappe-bench/apps/hrms/hrms/hr/doctype/shift_type/shift_type.py

#in line 24 comment out "is_half_holiday":

from erpnext.setup.doctype.holiday_list.holiday_list import is_holiday #is_half_holiday, is_holiday

save and re-try update.

I hope this helps someone encountering the same issue until it is permanently fixed :slight_smile: