API parameter, cannot use list parameter

Hi,

I’ve tried to pass list parameter into function using rest API, but list parameter passing in will got convert into first item of the list.

Code example:

@frappe.whitelist()
def read_list_param(list_param):
	print(type(list_param))
	print(list_param)

Input:

{
	"list_param": [1,2,3]
}

Output of read_list_param function

<class 'int'>
1

This is because there are conversion happening when received parameter.

Added by this commit. (Year 2014)

I don’t know why do we need this since list is a valid JSON.
I’ve tried and remove this conversion and the apps works just fine.
The question is do we still need this conversion ?

My use case is I want to pass list parameter into rest API.

2 Likes

Update,

Changing

try:
	frappe.local.form_dict = frappe._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
		for k, v in iteritems(args) })
except IndexError:
	frappe.local.form_dict = frappe._dict(args)

to

frappe.local.form_dict = frappe._dict(args)

Will break the app (on production setup, it doesn’t on development setup don’t know why)

For now my workaround is wrapping list into dict

Input

{
	"list_param": {
		"list": [1,2,3]
	}
}

Process

list_param = list_param.get('list')

Then every thing should work as intended.