frappe.exceptions.DoesNotExistError: DocType Server Script not found

From a backup of a v11 instance data set, I then restored that on a fresh v12 install.

I have run update a few times without errors and am stuck here wondering whether possibly a patch is required to fix this impasse?

Any advice or pointers would be appreciated thanks!

frappe@ubuntu1804lts:~/frappe-bench$ bench reload-doc core doctype server_script
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, 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/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.6/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 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 265, in reload_doc
    frappe.reload_doc(module, doctype, docname, force=context.force)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 805, in reload_doc
    return frappe.modules.reload_doc(module, dt, dn, force=force, reset_permissions=reset_permissions)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/utils.py", line 174, in reload_doc
    return import_files(module, dt, dn, force=force, reset_permissions=reset_permissions)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 27, in import_files
    reset_permissions=reset_permissions)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 32, in import_file
    ret = import_file_by_path(path, force, pre_process=pre_process, reset_permissions=reset_permissions)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 66, in import_file_by_path
    ignore_version=ignore_version, reset_permissions=reset_permissions)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py", line 141, in import_doc
    doc.insert()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 222, in insert
    self.run_method("before_insert")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 791, in run_method
    run_server_script_for_doc_event(self, method)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/server_script/server_script_utils.py", line 37, in run_server_script_for_doc_event
    scripts = get_server_script_map().get(doc.doctype, {}).get(EVENT_MAP[event], None)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/server_script/server_script_utils.py", line 61, in get_server_script_map
    filters={'disabled': 0})
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1305, in get_all
    return get_list(doctype, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1278, in get_list
    return frappe.model.db_query.DatabaseQuery(doctype).execute(None, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py", line 96, in execute
    result = self.build_and_run()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py", line 110, in build_and_run
    args = self.prepare_args()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py", line 137, in prepare_args
    self.build_conditions()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py", line 329, in build_conditions
    self.build_filter_conditions(self.filters, self.conditions)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py", line 350, in build_filter_conditions
    conditions.append(self.prepare_filter_condition(f))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py", line 357, in prepare_filter_condition
    f = get_filter(self.doctype, f)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/data.py", line 912, in get_filter
    meta = frappe.get_meta(f.doctype)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 765, in get_meta
    return frappe.model.meta.get_meta(doctype, cached=cached)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/meta.py", line 37, in get_meta
    meta = Meta(doctype)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/meta.py", line 83, in __init__
    super(Meta, self).__init__("DocType", doctype)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 105, in __init__
    self.load_from_db()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/meta.py", line 88, in load_from_db
    super(Meta, self).load_from_db()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 148, in load_from_db
    frappe.throw(_("{0} {1} not found").format(_(self.doctype), self.name), frappe.DoesNotExistError)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 364, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red')
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 350, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 316, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.DoesNotExistError: DocType Server Script not found

addendum:

There’s no question that DocType is present to be reloaded -

frappe@ubuntu1804lts:~/frappe-bench$ find . -name 'server_script.py'
./apps/frappe/frappe/core/doctype/server_script/server_script.py
frappe@ubuntu1804lts:~/frappe-bench$ find . -name '*.py' | xargs grep 'server_script'
./apps/frappe/frappe/core/doctype/server_script/server_script_utils.py:def run_server_script_api(method):
./apps/frappe/frappe/core/doctype/server_script/server_script_utils.py:	script_name = get_server_script_map().get('_api', {}).get(method)
./apps/frappe/frappe/core/doctype/server_script/server_script_utils.py:def run_server_script_for_doc_event(doc, event):
./apps/frappe/frappe/core/doctype/server_script/server_script_utils.py:	scripts = get_server_script_map().get(doc.doctype, {}).get(EVENT_MAP[event], None)
./apps/frappe/frappe/core/doctype/server_script/server_script_utils.py:def get_server_script_map():
./apps/frappe/frappe/core/doctype/server_script/server_script_utils.py:	script_map = frappe.cache().get_value('server_script_map')
./apps/frappe/frappe/core/doctype/server_script/server_script_utils.py:		enabled_server_scripts = frappe.get_all('Server Script',
./apps/frappe/frappe/core/doctype/server_script/server_script_utils.py:		for script in enabled_server_scripts:
./apps/frappe/frappe/core/doctype/server_script/server_script_utils.py:		frappe.cache().set_value('server_script_map', script_map)
./apps/frappe/frappe/core/doctype/server_script/server_script.py:		frappe.cache().delete_value('server_script_map')
./apps/frappe/frappe/core/doctype/server_script/test_server_script.py:		api_method = 'test_server_script',
./apps/frappe/frappe/core/doctype/server_script/test_server_script.py:		frappe.cache().delete_value('server_script_map')
./apps/frappe/frappe/core/doctype/server_script/test_server_script.py:		response = requests.post(get_site_url(frappe.local.site) + "/api/method/test_server_script")
./apps/frappe/frappe/utils/safe_exec.py:	if not frappe.conf.server_script_enabled:
./apps/frappe/frappe/handler.py:from frappe.core.doctype.server_script.server_script_utils import run_server_script_api
./apps/frappe/frappe/handler.py:	if run_server_script_api(cmd):
./apps/frappe/frappe/cache_manager.py:		'active_modules', 'assignment_rule', 'server_script_map', 'wkhtmltopdf_version')
./apps/frappe/frappe/model/document.py:from frappe.core.doctype.server_script.server_script_utils import run_server_script_for_doc_event
./apps/frappe/frappe/model/document.py:		run_server_script_for_doc_event(self, method)

So possibly part of the problem is the Server Script DocType is empty?

MariaDB [_1bd3e0294da19198]> select doctype_event,script, reference_doctype, api_method,script_type from `tabServer Script`;
Empty set (0.001 sec)

@clarkej This is not a code issue but a schema one. My preferred approach to problems like this is to create a version 11 bench and then upgrade the whole installation. Alternatively, doing bench migrate after you’ve installed the database, but that doesn’t always work.

Thanks Tyler!

“My preferred approach to problems like this is to create a version 11 bench and then upgrade the whole installation.”

Yes I must try this for myself - a colleague did and reported problems that I should have reviewed but did not!

“Alternatively, doing bench migrate after you’ve installed the database, but that doesn’t always work.”

This way here I tried code recompile and other basic tricks but no joy…

Cheers it’s all fun lol

After running bench update --patch and bench migrate a few times, the migration to ran to completion and the instance started up fine.

3 Likes

This solution worked for me where it was breaking at other patches but at this one “DocType Server Script not found” it’s just not working.

Yes, I also had that problem too with another instance update. In that case my/your only other option is to do a fresh install and restore your backed-up instance into that.

I faced issue like this and solved it , before it i was reinstall all docker and frappe to solve this issue and it’s back again ,so thanks you
my issue : " frappe.exceptions.DoesNotExistError: Website Theme Standard not found "

bench --site your site migrate