Link field in doctype to a virtual doctype throws KeyError

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.

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?

Solution :
- Use as_list from args of method get_list() in your Virtual DocType class.

Example :

Problem :

  • For Link field suggestion list of list require but due to Virtual Doctype’s json list of dict is returned.
1 Like

More Accurate :

@staticmethod
def get_list(args):
    data = BenchGroup.get_current_data()

    if args.get("as_list"):
        return [tuple(doc.values()) for doc in data.values()]

    return [frappe._dict(doc) for doc in data.values()]
1 Like