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?