V11 Site migrate fails because of Healthcare

After executing the command as shown below
Step 3 : Migrate site
bench --site site-name migrate

it fails . full traceroute

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 97, in <module>
    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 25, 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 39, in migrate
    frappe.modules.patch_handler.run_all()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 29, in run_all
    if not run_single(patchmodule = patch):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 63, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 83, in execute_patch
    frappe.get_attr(patchmodule.split()[0] + ".execute")()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v11_0/add_healthcare_service_unit_tree_root.py", line 14, in execute
    }).insert(ignore_permissions=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 223, in insert
    self._validate()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 446, in _validate
    self._validate_mandatory()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 725, in _validate_mandatory
    name=self.name))

Any pointers/guidance, would help.

Thanks

Before switching branches did you:
bench update --reset
bench update --patch

Hi,
Can you share the version from which you are migrating, not able to replicate as it didn’t fail in travis patch tests as well as in our dev instances.
Thanks

No. but tried now,

bench update --patch resulted in the same error.

it is fresh installation of master - production, done yesterday via easy install script and site was immediately migrated after completing setup wizard.

I didn’t run into any errors when migrating from the production develop branch either. Maybe once the easy install is completed try:
bench switch-to-develop
Then go through the setup wizard. Then follow the instructions you linked to above.

Switch to staging branch
bench switch-to-branch staging frappe
bench switch-to-branch staging erpnext

Setup requirements
bench setup requirements

Migrate site
bench --site site-name migrate

Restart supervisor.
bench restart

After large updates I sometimes have to
sudo service nginx restart
sudo supervisorctl restart all
From the frappe-bench directory. Possibly try this if you get stuck at some stage?
Good Luck

Thanks @jignesh_shah for reporting, have raised a PR to fix this.
Regards

Here’s the issue (and it’s not the only patch that is written this way, so it’s a Frappe-project-level design pattern problem). The writer of a patch must include checks to see if there is 1) a site installed and 2) setup has been completed. It is not reasonable to call post-setup methods before a site or company setup has been done; patches should not fail because of this.

I’m going to stop complaining now. Thank you @Ranjith for the fix and @jignesh_shah for starting the discussion.

1 Like

Thank you @tmatteson for locating the core issue and explaining the fix.