Error on latest update

Hi,
In the latest update we are getting 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/erp_healthcare/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 97, in
main()
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 18, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/erp_healthcare/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/home/erp_healthcare/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/home/erp_healthcare/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erp_healthcare/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erp_healthcare/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/erp_healthcare/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/home/erp_healthcare/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/erp_healthcare/frappe-bench/apps/frappe/frappe/commands/init.py”, line 25, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/commands/site.py”, line 222, in migrate
migrate(context.verbose, rebuild_website=rebuild_website)
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/migrate.py”, line 39, in migrate
frappe.modules.patch_handler.run_all()
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 29, in run_all
if not run_single(patchmodule = patch):
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 63, in run_single
return execute_patch(patchmodule, method, methodargs)
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 83, in execute_patch
frappe.get_attr(patchmodule.split()[0] + “.execute”)()
File “/home/erp_healthcare/frappe-bench/apps/frappe/frappe/patches/v11_0/update_list_user_settings.py”, line 22, in execute
order_by = order_by.replace(‘`’, ‘’).split(‘.’)[1]
IndexError: list index out of range

The value of order_by is modified desc

-Amit

Worked for me fine. Tried it on different backups. Can you tell me what was the value of order_by prior to replace and split ?

Ideally, order_by should be something like `tabDocType`.`modified` desc
Replace should yield tabDocType.modified desc and split should do ['tabDocType', 'modified desc']

@Zlash65 I checked on my local install also. It failed there as well for the older sites. For a new site it worked without an issue.

-Amit

@Zlash65
I checked the database. What it seems if there is a doctype where orderby is not set, then it shows :
“order_by”: “modified desc” otherwise it is defined as “order_by”: “<<doctype>>.modified desc” .

Can you kindly check.

-Amit

What version are you on ?

Can you share a screenshot of how order_by is looking like in your database ?
Maybe older version had a different way of storing it that wasn’t accounted for.

Facing same issue here.

Here is the output of SELECT * FROM `__UserSettings`;

***************************[ 1. row ]***************************
user    | Administrator
doctype | Membership
data    | {"updated_on": "Fri May 04 2018 11:30:16 GMT+0530", "List": {"sort_order": "desc", "filters": [], "sort_by": "modified"}, "last_view": "List"}
***************************[ 2. row ]***************************
user    | basawaraj@erpnext.org
doctype | Domain Settings
data    | {}
***************************[ 3. row ]***************************
user    | basawaraj@erpnext.org
doctype | Membership
data    | {"updated_on": "Fri May 04 2018 11:30:16 GMT+0530", "last_view": "List", "List": {"order_by": "`tabMembership`.`modified` desc", "filters": []}}

@Zlash65
suggested change
if (not order_by.startswith(“tab"+d['doctype']+"”) ) :
order_by = “tab"+d['doctype']+"”+“.modified desc”

Thats a sort of fix too, but its more like hardcoding modified desc.

order_by can be based on name, title, etc kinds of field so this wouldn’t work for most.

Here’s a potential fix for it that accounts for older order_by or an empty order_by -
https://github.com/frappe/frappe/pull/5580

2 Likes

@Zlash65 Thanks for the update. Appreciate you quick solution.

-Amit