frappe.exceptions.ValidationError: Standard roles cannot be disabled

Hello.

I have made some progress trying to upgrade from v12 to v13 by ensuring that the Python virtualenv matches the version of Python required by the installation (thanks to this thread for showing how to do that).

I have successfully run the install steps.

However, when running bench update --no-backup (I have to run with the --no-backup flag, I think because I am using a remote database server and backup fails with the Database or site_config.json may be corrupted error, I’ll deal with that later) I get an error on the erpnext step:

$ /home/erpnext/frappe-bench/env/bin/python -m pip install --quiet --upgrade -e /home/erpnext/frappe-bench/apps/erpnext 
$ yarn install
yarn install v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 1.17s.
Patching sites...
Migrating erp.comicrelief.com
Executing execute:frappe.reload_doc('core', 'doctype', 'doctype_action', force=True) #2019-09-23 in erp.comicrelief.com (erp_dev)
Success: Done in 0.581s
Executing execute:frappe.reload_doc('core', 'doctype', 'doctype_link', force=True) #2020-10-17 in erp.comicrelief.com (erp_dev)
Success: Done in 0.163s
Executing execute:frappe.reload_doc('core', 'doctype', 'document_naming_rule', force=True) in erp.comicrelief.com (erp_dev)
Success: Done in 0.266s
Executing execute:frappe.reload_doc('core', 'doctype', 'module_def') #2020-08-28 in erp.comicrelief.com (erp_dev)
Success: Done in 0.252s
Executing execute:frappe.reload_doc('core', 'doctype', 'has_role') in erp.comicrelief.com (erp_dev)
Success: Done in 0.153s
Executing execute:frappe.reload_doc('core', 'doctype', 'server_script') in erp.comicrelief.com (erp_dev)
Success: Done in 0.32s
Executing execute:frappe.reload_doc('social', 'doctype', 'energy_point_log') in erp.comicrelief.com (erp_dev)
Success: Done in 0.225s
Executing execute:frappe.reload_doc('social', 'doctype', 'energy_point_rule') in erp.comicrelief.com (erp_dev)
Success: Done in 0.229s
Executing frappe.patches.v13_0.rename_custom_client_script in erp.comicrelief.com (erp_dev)
Success: Done in 7.549s
Executing execute:frappe.reload_doc('core', 'doctype', 'report_column') in erp.comicrelief.com (erp_dev)
Success: Done in 0.198s
Executing execute:frappe.reload_doc('core', 'doctype', 'report_filter') in erp.comicrelief.com (erp_dev)
Success: Done in 0.154s
Executing execute:frappe.reload_doc('core', 'doctype', 'report') #2020-08-25 in erp.comicrelief.com (erp_dev)
Success: Done in 0.505s
Executing frappe.patches.v12_0.delete_duplicate_indexes  # 2022-12-15 in erp.comicrelief.com (erp_dev)
✓ dropped name index from tabFee Category
Success: Done in 1.463s
Executing frappe.patches.v12_0.change_existing_dashboard_chart_filters in erp.comicrelief.com (erp_dev)
Success: Done in 0.097s
Executing execute:frappe.delete_doc('DocType', 'Test Runner') # 2022-05-19 in erp.comicrelief.com (erp_dev)
Success: Done in 0.186s
Executing execute:frappe.db.set_default('desktop:home_page', 'workspace') in erp.comicrelief.com (erp_dev)
Success: Done in 0.145s
Executing execute:frappe.reload_doc('core', 'doctype', 'doctype', force=True) in erp.comicrelief.com (erp_dev)
Success: Done in 0.94s
Executing execute:frappe.reload_doc('custom', 'doctype', 'property_setter') in erp.comicrelief.com (erp_dev)
Success: Done in 0.522s
Executing frappe.patches.v13_0.remove_invalid_options_for_data_fields in erp.comicrelief.com (erp_dev)
Success: Done in 0.019s
Executing frappe.patches.v13_0.website_theme_custom_scss in erp.comicrelief.com (erp_dev)
Success: Done in 1.328s
Executing frappe.patches.v13_0.make_user_type in erp.comicrelief.com (erp_dev)
Success: Done in 1.196s
Executing frappe.patches.v13_0.set_existing_dashboard_charts_as_public in erp.comicrelief.com (erp_dev)
Success: Done in 0.817s
Executing frappe.patches.v13_0.set_path_for_homepage_in_web_page_view in erp.comicrelief.com (erp_dev)
Success: Done in 0.158s
Executing frappe.patches.v13_0.migrate_translation_column_data in erp.comicrelief.com (erp_dev)
Success: Done in 0.283s
Executing frappe.patches.v13_0.set_read_times in erp.comicrelief.com (erp_dev)
Success: Done in 0.476s
Executing frappe.patches.v13_0.remove_web_view in erp.comicrelief.com (erp_dev)
Success: Done in 0.015s
Executing frappe.patches.v13_0.site_wise_logging in erp.comicrelief.com (erp_dev)
Success: Done in 0.014s
Executing frappe.patches.v13_0.set_unique_for_page_view in erp.comicrelief.com (erp_dev)
Success: Done in 0.016s
Executing frappe.patches.v13_0.remove_tailwind_from_page_builder in erp.comicrelief.com (erp_dev)
Success: Done in 0.181s
Executing frappe.patches.v13_0.rename_onboarding in erp.comicrelief.com (erp_dev)
Success: Done in 0.015s
Executing frappe.patches.v13_0.email_unsubscribe in erp.comicrelief.com (erp_dev)
Success: Done in 0.126s
Executing execute:frappe.delete_doc("Web Template", "Section with Left Image", force=1) in erp.comicrelief.com (erp_dev)
Success: Done in 0.021s
Executing execute:frappe.delete_doc("DocType", "Onboarding Slide") in erp.comicrelief.com (erp_dev)
Success: Done in 0.014s
Executing execute:frappe.delete_doc("DocType", "Onboarding Slide Field") in erp.comicrelief.com (erp_dev)
Success: Done in 0.014s
Executing execute:frappe.delete_doc("DocType", "Onboarding Slide Help Link") in erp.comicrelief.com (erp_dev)
Success: Done in 0.013s
Executing frappe.patches.v13_0.update_date_filters_in_user_settings in erp.comicrelief.com (erp_dev)
Success: Done in 0.134s
Executing frappe.patches.v13_0.update_duration_options in erp.comicrelief.com (erp_dev)
Success: Done in 1.324s
Executing frappe.patches.v13_0.replace_old_data_import # 2020-06-24 in erp.comicrelief.com (erp_dev)
Success: Done in 0.092s
Executing frappe.patches.v13_0.create_custom_dashboards_cards_and_charts in erp.comicrelief.com (erp_dev)
Success: Done in 0.013s
Executing frappe.patches.v13_0.rename_is_custom_field_in_dashboard_chart in erp.comicrelief.com (erp_dev)
Success: Done in 0.021s
Executing frappe.patches.v13_0.add_standard_navbar_items # 2020-12-15 in erp.comicrelief.com (erp_dev)
Success: Done in 0.578s
Executing frappe.patches.v13_0.generate_theme_files_in_public_folder in erp.comicrelief.com (erp_dev)
Success: Done in 1.433s
Executing frappe.patches.v13_0.increase_password_length in erp.comicrelief.com (erp_dev)
Success: Done in 0.04s
Executing frappe.patches.v13_0.add_toggle_width_in_navbar_settings in erp.comicrelief.com (erp_dev)
Success: Done in 0.033s
Executing frappe.patches.v13_0.rename_notification_fields in erp.comicrelief.com (erp_dev)
Success: Done in 0.852s
Executing frappe.patches.v13_0.remove_duplicate_navbar_items in erp.comicrelief.com (erp_dev)
Success: Done in 0.032s
Executing frappe.patches.v13_0.set_social_icons in erp.comicrelief.com (erp_dev)
Success: Done in 0.125s
Executing frappe.patches.v12_0.set_default_password_reset_limit in erp.comicrelief.com (erp_dev)
Success: Done in 0.848s
Executing frappe.patches.v13_0.set_route_for_blog_category in erp.comicrelief.com (erp_dev)
Success: Done in 0.228s
Executing frappe.patches.v13_0.enable_custom_script in erp.comicrelief.com (erp_dev)
Success: Done in 0.018s
Executing frappe.patches.v13_0.update_newsletter_content_type in erp.comicrelief.com (erp_dev)
Success: Done in 0.404s
Executing execute:frappe.db.set_value('Website Settings', 'Website Settings', {'navbar_template': 'Standard Navbar', 'footer_template': 'Standard Footer'}) in erp.comicrelief.com (erp_dev)
Success: Done in 0.013s
Executing frappe.patches.v13_0.delete_event_producer_and_consumer_keys in erp.comicrelief.com (erp_dev)
Success: Done in 0.019s
Executing frappe.patches.v13_0.web_template_set_module #2020-10-05 in erp.comicrelief.com (erp_dev)
Success: Done in 0.336s
Executing frappe.patches.v13_0.remove_custom_link in erp.comicrelief.com (erp_dev)
Success: Done in 0.015s
Executing execute:frappe.delete_doc("DocType", "Footer Item") in erp.comicrelief.com (erp_dev)
Success: Done in 0.272s
Executing execute:frappe.reload_doctype('user') in erp.comicrelief.com (erp_dev)
Success: Done in 1.237s
Executing execute:frappe.reload_doctype('docperm') in erp.comicrelief.com (erp_dev)
Success: Done in 0.461s
Executing frappe.patches.v13_0.replace_field_target_with_open_in_new_tab in erp.comicrelief.com (erp_dev)
Success: Done in 0.24s
Executing frappe.core.doctype.role.patches.v13_set_default_desk_properties in erp.comicrelief.com (erp_dev)

Traceback (most recent call last):
  File "/home/erpnext/.pyenv/versions/3.8.10/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/erpnext/.pyenv/versions/3.8.10/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 110, in <module>
    main()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/erpnext/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/erpnext/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/erpnext/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/erpnext/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/erpnext/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/erpnext/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/erpnext/frappe-bench/env/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 31, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/commands/site.py", line 433, in migrate
    migrate(context.verbose, skip_failing=skip_failing, skip_search_index=skip_search_index)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/migrate.py", line 69, in migrate
    frappe.modules.patch_handler.run_all(skip_failing)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 47, in run_all
    run_patch(patch)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 36, in run_patch
    if not run_single(patchmodule=patch):
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 81, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 105, in execute_patch
    frappe.get_attr(patchmodule.split()[0] + ".execute")()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/core/doctype/role/patches/v13_set_default_desk_properties.py", line 13, in execute
    role_doc.save()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 312, in save
    return self._save(*args, **kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 349, in _save
    self.run_before_save_methods()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 1059, in run_before_save_methods
    self.run_method("validate")
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 943, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 1267, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 1249, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 940, in fn
    return method_object(*args, **kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/core/doctype/role/role.py", line 33, in validate
    self.disable_role()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/core/doctype/role/role.py", line 39, in disable_role
    frappe.throw(frappe._("Standard roles cannot be disabled"))
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 505, in throw
    msgprint(
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 480, in msgprint
    _raise_exception()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 435, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.ValidationError: Standard roles cannot be disabled

I can’t find any references to the ValidationError: Standard roles cannot be disabled anywhere.

Does anyone have any ideas about this one?

In the UI I have found the Role list, and I note that we have indeed disabled certain roles.

Roles System Manager, All and Administrator are all enabled.

Is it possible I need to enable some other roles in order for this upgrade to proceed?

OK, looks like the error comes from https://github.com/frappe/frappe/blob/49beb0c48e5d678875f409faa021174bc967247a/frappe/core/doctype/role/role.py#L60

and STANDARD_ROLES are defined as "Administrator", "System Manager", "Script Manager", "All", "Guest"

Seems that in my system Script Manager is disabled.

Now that I do not have access to the UI for my development box, does anyone know where in the database this role can be enabled/disabled?

bench console
frappe.db.set_value("Role", "Script Manager", "disabled", 0)
frappe.db.commit()
exit

Rerun bench migrate

You can pass --skip-failing with bench migrate to temporarily skip all failing patches and once the migration is over, run it again without that flag to make sure all patches are correctly applied.

1 Like

Thanks. This fixed my problem.

I have now managed to upgrade my dev system to v13 :slight_smile:

1 Like