V8 to v9 upgrade error domainification 'DocType' object has no attribute 'restrict_to_domain'

All

Trying to upgrade early v8.0.x to latest 9.1.2 and getting an error

AttributeError: 'DocType' object has no attribute 'restrict_to_domain'

Here is the full traceback

Executing frappe.patches.v8_0.update_records_in_global_search #11-05-2017 in erpnext-dev (0acfbbe28584367f)
Updating Global Search              : [========================================]Success
Executing execute:frappe.reload_doc('core', 'doctype', 'role') #2017-05-23 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 94, in <module>
    main()
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/utils/bench_helper.py", line 18, 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 217, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/migrate.py", line 31, 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 81, in execute_patch
    exec(patchmodule.split("execute:")[1],globals())
  File "<string>", line 1, in <module>
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/__init__.py", line 679, in reload_doc
    return frappe.modules.reload_doc(module, dt, dn, force=force, reset_permissions=reset_permissions)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/utils.py", line 153, in reload_doc
    return import_files(module, dt, dn, force=force, reset_permissions=reset_permissions)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/import_file.py", line 19, in import_files
    reset_permissions=reset_permissions)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/import_file.py", line 24, in import_file
    ret = import_file_by_path(path, force, pre_process=pre_process, reset_permissions=reset_permissions)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/import_file.py", line 58, in import_file_by_path
    ignore_version=ignore_version, reset_permissions=reset_permissions)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/import_file.py", line 131, in import_doc
    doc.insert()
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 245, in insert
    self.run_post_save_methods()
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 827, in run_post_save_methods
    self.run_method("on_update")
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 702, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 924, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 907, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 696, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 206, in on_update
    make_module_and_roles(self)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 767, in make_module_and_roles
    if doc.restrict_to_domain and not frappe.db.exists('Domain', doc.restrict_to_domain):
AttributeError: 'DocType' object has no attribute 'restrict_to_domain'

Thanks in advance.

Also experiencing the same issue. Any ideas?

Adding the row restrict_to_domain VARCHAR(40) to the table tabDocType fixed it for me

How do you know it is supposed to be a VARCHAR(40) ?

Another user also had this issue. He fixed it by installing it from scratch, but I guess he compared the tables of v8.0.x and v9, and possibly found the culprit. He suggested the fix - it made sense and I tried it and it worked.

Reference: Error in bench update to v9 when migrating - #5 by anibal.duardo

:raising_hand_man:

@dirkvdl16 @James_Robertson

ok so I altered the tabDocType table and now I get an error on Page object from a different update function.

Executing frappe.patches.v8_0.rename_print_to_printing 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 94, in <module>
    main()
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/utils/bench_helper.py", line 18, 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 217, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/migrate.py", line 31, 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 83, in execute_patch
    frappe.get_attr(patchmodule.split()[0] + ".execute")()
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/patches/v8_0/rename_print_to_printing.py", line 9, in execute
    frappe.reload_doc('printing', 'page', 'print_format_builder')
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/__init__.py", line 679, in reload_doc
    return frappe.modules.reload_doc(module, dt, dn, force=force, reset_permissions=reset_permissions)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/utils.py", line 153, in reload_doc
    return import_files(module, dt, dn, force=force, reset_permissions=reset_permissions)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/import_file.py", line 19, in import_files
    reset_permissions=reset_permissions)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/import_file.py", line 24, in import_file
    ret = import_file_by_path(path, force, pre_process=pre_process, reset_permissions=reset_permissions)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/import_file.py", line 58, in import_file_by_path
    ignore_version=ignore_version, reset_permissions=reset_permissions)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/modules/import_file.py", line 131, in import_doc
    doc.insert()
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 245, in insert
    self.run_post_save_methods()
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 827, in run_post_save_methods
    self.run_method("on_update")
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 702, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 924, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 907, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/model/document.py", line 696, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/core/doctype/page/page.py", line 53, in on_update
    make_module_and_roles(self, "roles")
  File "/home/erpnext/erpnext-dev/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 767, in make_module_and_roles
    if doc.restrict_to_domain and not frappe.db.exists('Domain', doc.restrict_to_domain):
AttributeError: 'Page' object has no attribute 'restrict_to_domain'

I tried adding the column to the tabPage table, with no luck.

ok had a breakthrough

this post - Error Executing erpnext.patches.v9_0.fix_subscription_next_date - #2 by rohit_w got me to thinking. So I tried

bench --force reload-doc core doctype page

and then ran another bench update and it worked!

2 Likes

For those following along, here are the workaround steps for this error if you are going from early v8 to latest (as of today) v9

bench mysql
ALTER TABLE tabDocType ADD COLUMN restrict_to_domain VARCHAR(40);
bench --force reload-doc core doctype page
bench update
bench restart

For me specifically this is from ERPNext: v8.0.21 and Frappe Framework: v8.0.32 to ERPNext: v9.1.4 and Frappe Framework: v9.1.7

2 Likes

Reading your first post after added restrict_to_domain to tabDocType, I saw that the tabPage table has a different length on the field restrict_to_domain, is a VARCHAR(140) … But I think that your solution is better than adding fields to every table with error…

As you say at the end , I think this problems occurs because our v8.x is too much old and in some point there’re are some error or update missing …

Good to know that you have a ERPNext updated and working again :wink:

1 Like

Thanks @James_Robertson for taking the time to work it out, I’m sure this will help other users

1 Like

#4312 should fix it.

1 Like

actually dear i am still facing trouble in the update process
even after trying your method.