Command bench switch-to-branch not changing to selected branch

Hello everyone,
Can someone help me for the following error?

Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 174, 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/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 94, in
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/local/lib/python2.7/site-packages/click/core.py”, line 764, in call
return self.main(*args, **kwargs)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 555, in invoke
return callback(*args, **kwargs)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/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 24, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py”, line 222, in migrate
migrate(context.verbose, rebuild_website=rebuild_website)
File “/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py”, line 32, in migrate
frappe.model.sync.sync_all(verbose=verbose)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py”, line 19, in sync_all
sync_for(app, force, verbose=verbose, reset_permissions=reset_permissions)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py”, line 45, in sync_for
reset_permissions=reset_permissions, for_sync=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py”, line 58, 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 132, in import_doc
doc.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 248, in insert
self.run_post_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 889, in run_post_save_methods
self.run_method(“on_update”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 757, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1026, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1009, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 751, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 238, in on_update
self.run_module_method(“on_doctype_update”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 302, in run_module_method
module = load_doctype_module(self.name, self.module)
File “/home/frappe/frappe-bench/apps/frappe/frappe/modules/utils.py”, line 187, in load_doctype_module
raise ImportError(‘Module import failed for {0} ({1})’.format(doctype, module_name + ’ Error: ’ + str(e)))
ImportError: Module import failed for Exchange Rate Revaluation (erpnext.accounts.doctype.exchange_rate_revaluation.exchange_rate_revaluation Error: cannot import name get_permitted_documents)

Have you updated your system to latest version etc?
Can you share/show your traceback screens, and environment, versions etc.

Import problems are most commonly linked to incorrect data structure of the import file. I always try to create one record of the type I want to import, then export it with template, and fill in the data in the correct columns, then reimport it back into the system. There are also some weirdnesses in xlsx files that you have to check (eg. incompatible date/locale formatting etc)

The error occur when I try to do bench update

frappe@erp:~/frappe-bench$ bench update
INFO:bench.utils:updating bench
INFO:bench.utils:git pull
Already up to date.
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 47 (delta 35), reused 38 (delta 29), pack-reused 0
Unpacking objects: 100% (47/47), done.
From GitHub - frappe/frappe: Low code web framework for real world applications, in Python and Javascript
2fa90a29b…44f52aa5a develop → upstream/develop
INFO:bench.utils:./env/bin/pip install Pillow
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: Pillow in ./env/lib/python2.7/site-packages (5.3.0)
INFO:bench.app:pulling frappe
INFO:bench.utils:git pull upstream v10.x.x
From GitHub - frappe/frappe: Low code web framework for real world applications, in Python and Javascript

  • branch v10.x.x → FETCH_HEAD
    Already up to date.
    INFO:bench.utils:find . -name “*.pyc” -delete
    INFO:bench.app:pulling erpnext
    INFO:bench.utils:git pull upstream master
    From GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP)
  • branch master → FETCH_HEAD
    Already up to date.
    INFO:bench.utils:find . -name “*.pyc” -delete
    Updating Python libraries…
    INFO:bench.utils:./env/bin/pip install --upgrade pip
    DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.
    Requirement already up-to-date: pip in ./env/lib/python2.7/site-packages (19.0.3)
    INFO:bench.utils:./env/bin/pip install -q -r /home/frappe/.bench/requirements.txt
    DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.
    INFO:bench.app:installing frappe
    INFO:bench.utils:./env/bin/pip install -q -e ./apps/frappe
    DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.
    INFO:bench.app:installing erpnext
    INFO:bench.utils:./env/bin/pip install -q -e ./apps/erpnext
    DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.
    Updating node packages…
    INFO:bench.utils:npm install
    npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
    npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.2.7
    npm WARN frappe@ No description
    Backing up sites…
    Patching sites…
    Migrating mysite.com
    Updating DocTypes for frappe : [========================================]
    Traceback (most recent call last):
    File “/usr/lib/python2.7/runpy.py”, line 174, 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/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 94, in
    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/local/lib/python2.7/site-packages/click/core.py”, line 764, in call
    return self.main(*args, **kwargs)
    File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 717, in main
    rv = self.invoke(ctx)
    File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 555, in invoke
    return callback(*args, **kwargs)
    File “/home/frappe/frappe-bench/env/local/lib/python2.7/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 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py”, line 222, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py”, line 32, in migrate
    frappe.model.sync.sync_all(verbose=verbose)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py”, line 19, in sync_all
    sync_for(app, force, verbose=verbose, reset_permissions=reset_permissions)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/model/sync.py”, line 45, in sync_for
    reset_permissions=reset_permissions, for_sync=True)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/modules/import_file.py”, line 58, 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 132, in import_doc
    doc.insert()
    File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 248, in insert
    self.run_post_save_methods()
    File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 889, in run_post_save_methods
    self.run_method(“on_update”)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 757, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1026, in composer
    return composed(self, method, *args, **kwargs)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1009, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
    File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 751, in
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 238, in on_update
    self.run_module_method(“on_doctype_update”)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 302, in run_module_method
    module = load_doctype_module(self.name, self.module)
    File “/home/frappe/frappe-bench/apps/frappe/frappe/modules/utils.py”, line 187, in load_doctype_module
    raise ImportError(‘Module import failed for {0} ({1})’.format(doctype, module_name + ’ Error: ’ + str(e)))
    ImportError: Module import failed for Exchange Rate Revaluation (erpnext.accounts.doctype.exchange_rate_revaluation.exchange_rate_revaluation Error: cannot import name get_permitted_documents)
    frappe@erp:~/frappe-bench$

Also, I’ve changed the branch for frappe and erpnext to v10.x.x but when I run bench update, the log showed that my erpnext is on master. Is it the cause for this issue?

INFO:bench.app:pulling erpnext
INFO:bench.utils:git pull upstream master
From GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP)
branch master → FETCH_HEAD
Already up to date.

I have resolved my issue. The cause was the unsuccessful change of branch using bench switch-to-branch command. The command bench switch-to-branch v10.x.x did not work because there were some minor error in my erpnext git config file where it only fetch master branch.

What I did was change the frappe-bench/apps/erpnext/.git/config from below

[remote “upstream”]
url = GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP)
fetch = +refs/heads/master:refs/remotes/upstream/master

to

[remote “upstream”]
url = GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP)
fetch = +refs/heads/*:refs/remotes/upstream/*

then run git fetch from frappe-bench/apps/erpnext folder,
then switch branch using bench switch-to-branch v10.x.x from frappe-bench directory. I am staying in V10 so I switch to the v10.x.x branch.