Bench migrate - TypeError: cannot pickle 'module' object

Before I have switch to frappe 13 to 14 after bench migrate I’m getting this error and dont understand what it is

Migrating test.site4
Executing execute:frappe.delete_doc('DocType', 'Test Runner') # 2022-05-19 in test.site4 (site4)
Building search index for test.site4
Retrieving Routes                   : [========================================] 100%
Building Index                      : [========================================] 100%
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/sagar_p/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 109, in <module>
    main()
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/sagar_p/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/sagar_p/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/sagar_p/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sagar_p/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sagar_p/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sagar_p/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/sagar_p/frappe-bench/env/lib/python3.10/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/commands/site.py", line 552, in migrate
    SiteMigration(
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/migrate.py", line 175, in run
    self.run_schema_updates()
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/migrate.py", line 41, in wrapper
    ret = method(*args, **kwargs)
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/migrate.py", line 110, in run_schema_updates
    frappe.modules.patch_handler.run_all(
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 75, in run_all
    run_patch(patch)
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 62, in run_patch
    if not run_single(patchmodule=patch):
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 150, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 189, in execute_patch
    update_patch_log(patchmodule)
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 209, in update_patch_log
    frappe.get_doc({"doctype": "Patch Log", "patch": patchmodule}).insert(ignore_permissions=True)
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/__init__.py", line 1180, in get_doc
    doc = frappe.model.document.get_doc(*args, **kwargs)
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/model/document.py", line 72, in get_doc
    controller = get_controller(doctype)
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/model/base_document.py", line 81, in get_controller
    site_controllers[doctype] = _get_controller()
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/model/base_document.py", line 55, in _get_controller
    class_overrides = frappe.get_hooks("override_doctype_class")
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/__init__.py", line 1476, in get_hooks
    hooks = _dict(cache().get_value("app_hooks", _load_app_hooks))
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py", line 82, in get_value
    self.set_value(original_key, val, user=user)
  File "/home/sagar_p/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py", line 50, in set_value
    self.set(key, pickle.dumps(val))
TypeError: cannot pickle 'module' object

In one of your hooks.py you have a module object, since it can’t be cached redis is throwing error.

e.g.

# hooks.py

import some_module

hook_name = some_module

Or even if you’ve imported something there it might fail. hooks.py should be just plain config file. :sweat_smile: