api: don't crash /api/forms when there are no formdefs (#32415)
This commit is contained in:
parent
dcb0b0fc58
commit
e916dcf8d2
|
@ -1863,6 +1863,10 @@ def test_api_global_listing(pub, local_user):
|
|||
role = Role(name='test')
|
||||
role.store()
|
||||
|
||||
# check there's no crash if there are no formdefs
|
||||
resp = get_app(pub).get(sign_uri('/api/forms/', user=local_user))
|
||||
assert len(resp.json['data']) == 0
|
||||
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'test'
|
||||
|
|
|
@ -217,6 +217,13 @@ class ApiFormsDirectory(Directory):
|
|||
self.check_access()
|
||||
get_request().user = get_user_from_api_query_string() or get_request().user
|
||||
|
||||
if FormDef.count() == 0:
|
||||
# early return, this avoids running a query against a missing SQL view.
|
||||
get_response().set_content_type('application/json')
|
||||
return json.dumps({'data': []},
|
||||
cls=misc.JSONEncoder,
|
||||
encoding=get_publisher().site_charset)
|
||||
|
||||
from wcs import sql
|
||||
|
||||
management_directory = ManagementDirectory()
|
||||
|
|
Loading…
Reference in New Issue