diff --git a/tests/test_api.py b/tests/test_api.py index cfa6456fb..912e7b70f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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' diff --git a/wcs/api.py b/wcs/api.py index dc75e23ea..906701620 100644 --- a/wcs/api.py +++ b/wcs/api.py @@ -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()