[Solved] How To Set Default Company Using Command Line To Fix Update Failure

I am facing a sticky situation. I was trying to update my instance and encountered this error:

frappe.exceptions.DoesNotExistError: Company None not found

Full traceback:

Traceback (most recent call last):
File “/usr/lib/python3.6/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/usr/lib/python3.6/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/octo5/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 97, in
main()
File “/home/octo5/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 18, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/octo5/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 764, in call
return self.main(*args, **kwargs)
File “/home/octo5/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/home/octo5/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/octo5/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/octo5/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/octo5/frappe-bench/env/lib/python3.6/site-packages/click/core.py”, line 555, in invoke
return callback(*args, **kwargs)
File “/home/octo5/frappe-bench/env/lib/python3.6/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/octo5/frappe-bench/apps/frappe/frappe/commands/init.py”, line 25, in func
ret = f(frappe.dict(ctx.obj), *args, **kwargs)
File “/home/octo5/frappe-bench/apps/frappe/frappe/commands/site.py”, line 233, in migrate
migrate(context.verbose, rebuild_website=rebuild_website, skip_failing=skip_failing)
File “/home/octo5/frappe-bench/apps/frappe/frappe/migrate.py”, line 48, in migrate
frappe.modules.patch_handler.run_all(skip_failing)
File “/home/octo5/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 41, in run_all
run_patch(patch)
File “/home/octo5/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 30, in run_patch
if not run_single(patchmodule = patch):
File “/home/octo5/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 71, in run_single
return execute_patch(patchmodule, method, methodargs)
File “/home/octo5/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 91, in execute_patch
frappe.get_attr(patchmodule.split()[0] + “.execute”)()
File “/home/octo5/frappe-bench/apps/erpnext/erpnext/patches/v12_0/add_default_dashboards.py”, line 8, in execute
add_dashboards()
File “/home/octo5/frappe-bench/apps/erpnext/erpnext/setup/setup_wizard/operations/install_fixtures.py”, line 505, in add_dashboards
dashboard_data = get_default_dashboards()
File “/home/octo5/frappe-bench/apps/erpnext/erpnext/setup/setup_wizard/data/dashboard_charts.py”, line 7, in get_default_dashboards
company = frappe.get_doc(“Company”, frappe.defaults.get_defaults().company)
File “/home/octo5/frappe-bench/apps/frappe/frappe/init.py”, line 734, in get_doc
doc = frappe.model.document.get_doc(*args, **kwargs)
File “/home/octo5/frappe-bench/apps/frappe/frappe/model/document.py”, line 69, in get_doc
return controller(*args, **kwargs)
File “/home/octo5/frappe-bench/apps/frappe/frappe/model/document.py”, line 104, in init
self.load_from_db()
File “/home/octo5/frappe-bench/apps/frappe/frappe/model/document.py”, line 147, in load_from_db
frappe.throw(
(“{0} {1} not found”).format(
(self.doctype), self.name), frappe.DoesNotExistError)
File “/home/octo5/frappe-bench/apps/frappe/frappe/init.py”, line 360, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/octo5/frappe-bench/apps/frappe/frappe/init.py”, line 346, in msgprint
_raise_exception()
File “/home/octo5/frappe-bench/apps/frappe/frappe/init.py”, line 315, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.DoesNotExistError: Company None not found

My assumption is that default company is not set in global defaults but i can’t go back into my site as i am presented with your system is being updated error 503. Can anyone help me with how to set the default company from terminal so i can complete the update? I’m in a bind as my entire instance is down. I would appreciate the help.

Highly reliable source revant_one notes this neat trick - I have not had to use it - but exercise caution for sure [Mar-2017] Showing there were error during setup ERPNext - #19 by revant_one

Thanks for the reply @clarkej

I set up a demo instance and restored a backup of the site and did this in bench console:

In [1]: args = {
…: “company_name”:“Octo5 Holdings Limited”,
…: }
In [2]: from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
In [3]: setup_complete(args)
In [4]:

Still no luck with resolving the issue as i still get the error when i bench migrate/bench update and desk is still stuck on error 503. I’m in a big fix. I didn’t imagine this error popping up when i attempted to update from v12.0.8 to v12.1.1 and i note that this was not an issue when i upgrade from v12.0.3 to v12.0.8.

Other ideas to try -

  1. run bench update a few more times.

  2. with bench start running in one console, run bench update in a separate one

  3. comment out the add_default_dashboards patch

  4. run bench export-fixtures to identify a problem fixture

1 Like

@clarkej How do i achieve this as i know this is where the problem is?

Tried other options but so far no luck.

this line here

oh my gosh!!! thanks for the help.:hugs:

It wasn’t exactly straightforward as commenting out the patch as that was good for migrate but i still couldn’t update as i then faced an uncommitted change in erpnext and my live instance was stuck in update mode so migrating alone didn’t restore it.

In order to overcome this, i set up a new instance, restored my “defective” backup and commented out the patch before migrating. I was then able to login, set default company in global defaults, backup and restore to my live instance. And then my live instance updated successfully.

It was a long route but problem solved!!! thanks once again.

You can help close the issue if you think someone else may not need any other info to resolve a similar issue.

1 Like

Hi,

I faced the same situation, With a lot of code browsing it turned to be creating a record in the database table ‘tabDefaultValue’ manually. I used phpmyadmin to add the record for company.

defkey = company
defvalue = <your_company_name>

I used online python compiler to get value for

name = <output from the below code>

import hashlib, time

def random_string(length):
	"""generate a random string"""
	import string
	from random import choice
	return ''.join([choice(string.ascii_letters + string.digits) for i in range(length)])
	
digest = hashlib.sha224((("DefaultValue") + repr(time.time()) + repr(random_string(8))).encode()).hexdigest()
print digest[:10]

Thats it, bench update went smooth their after.

This is a much easier route. However I have been unable to deploy phpmyadmin to my instance. If you could help with steps to do this it will be much appreciated.

Hi,

Create /etc/nginx/snippets/phpmyadmin.conf and copy the below configuration content in it. Then in the end of the server block of file /etc/nginx/sites-enabled/default add include snippets/phpmyadmin.conf;

    root /usr/share/;
    index index.php index.html index.htm;
    location ~ ^/phpmyadmin/(.+\.php)$ {
        try_files $uri =404;
        root /usr/share/;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }

    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
        root /usr/share/;
    }
}

I didn’t get this part. The file default is in sites-available directory and sites-enabled directory is empty. Nearly everything in the file is commented out and i would like to mention that i did not install php.

I request you to check how to enable nginx configurations. Its all out there.

I too have this same “Company None not found” problem but I don’t have the experience to easily follow the recommendations on this post with out more detail. is there a way to do this without setting up a new instance or directly modifying the database? Will there be a patch to fix this problem?

The issue is officially fixed with this patch.

Thanks for including the link excellent learning for me mujeerhashmi…