Interesting, so I am getting same error as you, but from a different function call on the upgrade. For the record, here is the entire stack trace.
Executing execute:frappe.utils.global_search.setup_global_search_table() in erpnext-dev (0acfbbe28584367f)
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, 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/erpnext/erpnext-dev/apps/frappe/frappe/utils/bench_helper.py", line 79, in <module>
main()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/utils/bench_helper.py", line 16, in main
click.Group(commands=commands)(prog_name='bench')
File "/home/erpnext/erpnext-dev/env/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/home/erpnext/erpnext-dev/env/local/lib/python2.7/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/home/erpnext/erpnext-dev/env/local/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/erpnext/erpnext-dev/env/local/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/erpnext/erpnext-dev/env/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/erpnext/erpnext-dev/env/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/home/erpnext/erpnext-dev/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/commands/__init__.py", line 24, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/commands/site.py", line 210, in migrate
migrate(context.verbose, rebuild_website=rebuild_website)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/migrate.py", line 30, in migrate
frappe.modules.patch_handler.run_all()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/patch_handler.py", line 29, in run_all
if not run_single(patchmodule = patch):
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/patch_handler.py", line 63, in run_single
return execute_patch(patchmodule, method, methodargs)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/patch_handler.py", line 84, in execute_patch
update_patch_log(patchmodule)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/patch_handler.py", line 101, in update_patch_log
frappe.get_doc({"doctype": "Patch Log", "patch": patchmodule}).insert()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 190, in insert
self.validate_higher_perm_levels()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 451, in validate_higher_perm_levels
has_access_to = self.get_permlevel_access()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 466, in get_permlevel_access
roles = frappe.get_roles()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/__init__.py", line 361, in get_roles
return get_user().get_roles()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/__init__.py", line 349, in get_user
local.user_perms = UserPermissions(local.session.user)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/utils/user.py", line 37, in __init__
self.setup_user()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/utils/user.py", line 53, in setup_user
user_doc = frappe.cache().hget("user_doc", self.name, get_user_doc)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/utils/redis_wrapper.py", line 171, in hget
value = generator()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/utils/user.py", line 43, in get_user_doc
user = frappe.get_doc("User", self.name).as_dict()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/__init__.py", line 602, in get_doc
return frappe.model.document.get_doc(arg1, arg2)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 51, in get_doc
return controller(arg1, arg2)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 84, in __init__
self.load_from_db()
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 130, in load_from_db
self.set(df.fieldname, children)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/base_document.py", line 122, in set
self.extend(key, value)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/base_document.py", line 148, in extend
self.append(key, v)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/base_document.py", line 136, in append
value = self._init_child(value, key)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/base_document.py", line 163, in _init_child
value = get_controller(value["doctype"])(value)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/base_document.py", line 34, in get_controller
module = load_doctype_module(doctype, module_name)
File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/utils.py", line 184, in load_doctype_module
raise ImportError, 'Module import failed for {0} ({1})'.format(doctype, module_name)
ImportError: Module import failed for UserRole (frappe.core.doctype.userrole.userrole)