Bug description
I'm reopening the issue that was previously reported here: https://github.com/apache/superset/issues/15457 I'll quote that original issue here, the only difference is that I'm using 4.1.2.
When creating a dashboard with the API (POST `/dashboard/), the response indicates success but the resulting dashboard is not functional. The charts do not appear to be operative.
Expected results Creation of a dashboard with the API should result in a properly functioning dashboard / charts, just the same as if the dashboard were created manually with the UI.
Actual results Dashboard is successfully created, however the charts are nonoperational.
Screenshots Screen Shot 2021-06-29 at 9 22 20 AM
How to reproduce the bug Prerequisites:
CSRF is disabled (add WTF_CSRF_ENABLED = False to superset/config.py) Install curl for testing the API and jq for parsing JSON SUPERSET_HOST=localhost:8088 SUPERSET_USER=admin; SUPERSET_PASSWORD=admin Obtain a TOKEN TOKEN=$(curl -s http://$SUPERSET_HOST/api/v1/security/login -H 'accept: application/json' -H 'Content-Type: application/json' -d '{ "password": "'$SUPERSET_PASSWORD'", "provider": "db", "refresh": true, "username": "'$SUPERSET_USER'" }' | jq -r .access_token)
Determine the UUID of the "Daily Totals" chart Since there is no way to discover the UUID of a chart from the API (see related issue below), you need to manually create a dashboard containing a chart (for this simple test case) and then GET /dashboard/{pk} on that dashboard. The UUID value of the "Daily Totals" chart will be in the position_json attribute of the dashboard.
Create a dashboard with the chart (NOTE: you must include the UUID of the "Daily Totals" chart from above step) curl -s 'http://'$SUPERSET_HOST'/api/v1/dashboard/' \ -H 'Authorization: Bearer '$TOKEN'' \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "dashboard_title": "TestDashboard", "json_metadata": "{\"timed_refresh_immune_slices\": [], \"expanded_slices\": {}, \"refresh_frequency\": 0, \"default_filters\": \"{}\", \"color_scheme\": null}", "position_json": "{\"CHART-w2_C20sz-l\":{\"children\":[],\"id\":\"CHART-w2_C20sz-l\",\"meta\":{\"chartId\":67,\"height\":50,\"sliceName\":\"Daily Totals\",\"uuid\":\"5ffc22e4-244e-491d-965b-b7d178845df2\",\"width\":4},\"parents\":[\"ROOT_ID\",\"GRID_ID\",\"ROW-qDUg8z__N5\"],\"type\":\"CHART\"},\"DASHBOARD_VERSION_KEY\":\"v2\",\"GRID_ID\":{\"children\":[\"ROW-qDUg8z__N5\"],\"id\":\"GRID_ID\",\"parents\":[\"ROOT_ID\"],\"type\":\"GRID\"},\"HEADER_ID\":{\"id\":\"HEADER_ID\",\"meta\":{\"text\":\"[ untitled dashboard ]\"},\"type\":\"HEADER\"},\"ROOT_ID\":{\"children\":[\"GRID_ID\"],\"id\":\"ROOT_ID\",\"type\":\"ROOT\"},\"ROW-qDUg8z__N5\":{\"children\":[\"CHART-w2_C20sz-l\"],\"id\":\"ROW-qDUg8z__N5\",\"meta\":{\"background\":\"BACKGROUND_TRANSPARENT\"},\"parents\":[\"ROOT_ID\",\"GRID_ID\"],\"type\":\"ROW\"}}", "published": false }'
An HTTP 200 Success response is returned with this body:
{ "id": 13, "result": { "dashboard_title": "TestDashboard", "json_metadata": "{\"timed_refresh_immune_slices\": [], \"expanded_slices\": {}, \"refresh_frequency\": 0, \"default_filters\": \"{}\", \"color_scheme\": null}", "position_json": "{\"CHART-w2_C20sz-l\":{\"children\":[],\"id\":\"CHART-w2_C20sz-l\",\"meta\":{\"chartId\":67,\"height\":50,\"sliceName\":\"Daily Totals\",\"uuid\":\"5ffc22e4-244e-491d-965b-b7d178845df2\",\"width\":4},\"parents\":[\"ROOT_ID\",\"GRID_ID\",\"ROW-qDUg8z__N5\"],\"type\":\"CHART\"},\"DASHBOARD_VERSION_KEY\":\"v2\",\"GRID_ID\":{\"children\":[\"ROW-qDUg8z__N5\"],\"id\":\"GRID_ID\",\"parents\":[\"ROOT_ID\"],\"type\":\"GRID\"},\"HEADER_ID\":{\"id\":\"HEADER_ID\",\"meta\":{\"text\":\"[ untitled dashboard ]\"},\"type\":\"HEADER\"},\"ROOT_ID\":{\"children\":[\"GRID_ID\"],\"id\":\"ROOT_ID\",\"type\":\"ROOT\"},\"ROW-qDUg8z__N5\":{\"children\":[\"CHART-w2_C20sz-l\"],\"id\":\"ROW-qDUg8z__N5\",\"meta\":{\"background\":\"BACKGROUND_TRANSPARENT\"},\"parents\":[\"ROOT_ID\",\"GRID_ID\"],\"type\":\"ROW\"}}", "published": false } }
Using the Superset UI, examine the "TestDashboard" just created, the chart on the dashboard displays the message (see screenshot) "There is no chart definition associated with this component, could it have been deleted? Delete this container and save to remove this message."
Note: After creation of a dashboard with the API, if you manually use the UI to edit the dashboard and do a simple change (such as changing the name of the dashboard) and then save it, the dashboard will be operational (after a reload). Whatever is "missing" from the dashboard (links to the charts?) is created at this time.
Screenshots/recordings
After creating the dashboard using the REST API
After editing the dashboard and changing its name:
Superset version
4.1.2
Python version
3.11
Node version
16
Browser
Chrome
Additional context
No response
Checklist
- [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [ ] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Comment From: dosubot[bot]
Hey @AxelFurlanF! 👋 I'm here to help you with any bugs, questions, or contributions you have in mind. Let's get to the bottom of this together while we wait for a human maintainer.
The issue you're experiencing with creating a dashboard via the API in Apache Superset, where the charts are nonoperational until the dashboard is manually edited and saved through the UI, might be related to missing links or definitions that are not established during the API creation process.
One key aspect to check is the position_json
attribute, which defines the layout and positioning of charts within the dashboard. This JSON object must be correctly structured to ensure that all components, such as charts, are properly linked and displayed. Each component should have a unique key and include necessary metadata like chartId
, height
, width
, and uuid
[1][2].
To troubleshoot and potentially resolve this issue, you can:
- Verify that the
position_json
is correctly formatted and includes all necessary metadata for each chart. - Ensure that the
uuid
andchartId
in theposition_json
match the actual chart identifiers in your Superset instance. - Consider manually editing the
position_json
to match the structure of a dashboard created through the UI, as this might reveal any discrepancies.
If these steps do not resolve the issue, it may be necessary to further investigate the API's response and compare it with the UI's behavior to identify any missing components or configurations.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
Comment From: sadpandajoe
@AxelFurlanF couple of questions: 1. how are you exporting your dashboards? Through the UI or through the API? 2. when importing, if you are using the UI to import, do charts and database also get imported correctly for you?
Comment From: AxelFurlanF
@sadpandajoe hey, thanks for answering.
I'm getting the data of a sample dashboard using the /api/v1/dashboard/{id}
endpoint. And copying the json_metadata
and position_json
, to then be used by doing a POST request to /api/v1/dashboard/
.
I'm not creating any other object like datasets or charts, because I assume they already exist since they're being used in this sample dash
Comment From: paketep
Hello,
having the same issue, chart creation doesn't return uuid, and even adding the chart manually to a dashboard, getting the uuid with an export and then trying via the API, I still end up with the "There is no chart definition associated with this component, could it have been deleted? Delete this container and save to remove this message." error.
Very disappointing that this issue has been open for more than two months in what it should be the very first and most basic use of the API (creating a dashboard and adding a chart!!!!). Why have an API otherwise?
It would be super helpful to have a basic working example in the docs (if there is one, I haven't been able to find it).