Link doctype working but shows error while clicking on linked field

image
I am getting data from external api and mapping it to virtual doctype. Now linking that virtual doctype to another doctype field to create a lookup throws Keyerror 0.

By looking the server found that error occurs in frappe/frappe/desk/search.py

def relevance_sorter(key, query, as_dict):

value = _(key.name if as_dict else key[0])
return (cstr(value).lower().startswith(query.lower()) is not True, value)

The key here, in my case, shows dictionary and as_dict as False. Generally, the key has tuple data. So what can I do solve this error or is there any other way to implement this?

Did you solve this issue? I am experiencing the same problem.

The answer can be found here … Overriding Link Query By Custom Script

@Harsh_Shiroya try this
if isinstance(key, tuple):
value = _(key[0] if as_dict else key.name)
elif isinstance(key, dict):
value = _(key.name if as_dict else key.get(‘name’))
else:
value = _(str(key))
return (str(value).lower().startswith(query.lower()) is not True, value)