diff --git a/superset/views/api.py b/superset/views/api.py index 84c27d2fac18e..267d41dd75b8c 100644 --- a/superset/views/api.py +++ b/superset/views/api.py @@ -86,7 +86,7 @@ def query_form_data(self) -> FlaskResponse: # pylint: disable=no-self-use update_time_range(form_data) - return json.dumps(form_data) + return self.json_response(form_data) @api @handle_api_exception diff --git a/tests/integration_tests/charts/api_tests.py b/tests/integration_tests/charts/api_tests.py index 2db0cc7de301a..c5e88426fad80 100644 --- a/tests/integration_tests/charts/api_tests.py +++ b/tests/integration_tests/charts/api_tests.py @@ -1424,6 +1424,20 @@ def test_get_time_range(self): self.assertEqual(rv.status_code, 200) self.assertEqual(len(data["result"]), 3) + def test_query_form_data(self): + """ + Chart API: Test query form data + """ + self.login(username="admin") + slice = db.session.query(Slice).first() + uri = f"api/v1/form_data/?slice_id={slice.id if slice else None}" + rv = self.client.get(uri) + data = json.loads(rv.data.decode("utf-8")) + self.assertEqual(rv.status_code, 200) + self.assertEqual(rv.content_type, "application/json") + if slice: + self.assertEqual(data["slice_id"], slice.id) + @pytest.mark.usefixtures( "load_unicode_dashboard_with_slice", "load_energy_table_with_slice",