api: fix submission of empty map field data (#15504)
This commit is contained in:
parent
bec4f243b8
commit
4a51316f09
|
@ -682,6 +682,20 @@ def test_formdef_submit_from_wscall(pub, local_user):
|
|||
new_formdata = formdef.data_class().get(resp.json['data']['id'])
|
||||
assert str(new_formdata.user_id) == str(local_user.id)
|
||||
|
||||
# test missing map data
|
||||
del formdata.data['5']
|
||||
|
||||
payload = json.loads(
|
||||
json.dumps(formdata.get_json_export_dict(),
|
||||
cls=qommon.misc.JSONEncoder,
|
||||
encoding=get_publisher().site_charset))
|
||||
signed_url = sign_url('http://example.net/api/formdefs/test/submit?orig=coucou', '1234')
|
||||
url = signed_url[len('http://example.net'):]
|
||||
|
||||
resp = get_app(pub).post_json(url, payload)
|
||||
assert resp.json['err'] == 0
|
||||
new_formdata = formdef.data_class().get(resp.json['data']['id'])
|
||||
assert new_formdata.data.get('5') is None
|
||||
|
||||
def test_categories(pub):
|
||||
FormDef.wipe()
|
||||
|
|
|
@ -59,7 +59,7 @@ def posted_json_data_to_formdata_data(formdef, data):
|
|||
for field in formdef.get_all_fields():
|
||||
if not hasattr(field, 'from_json_value'):
|
||||
continue
|
||||
if not field.id in data:
|
||||
if data.get(field.id) is None:
|
||||
continue
|
||||
data[field.id] = field.from_json_value(data[field.id])
|
||||
|
||||
|
|
Loading…
Reference in New Issue