superset: 4.0 - Imported charts shows error on embedding
Bug description
「Guest user cannot modify chart payload」 Error is displayed for imported charts. It’s related to this issue, but with a specific reproduction flow. (https://github.com/apache/superset/issues/27177)
How to reproduce the bug
- Create 2 superset 4.0 instances
- Create a dashboard with a few charts (tested with “big-number” chart)
- Export the dashboard and import it into the other superset instance
- Try to embed the dashboard (using the sdk) into a web app
- 「Guest user cannot modify chart payload」Error is displayed for each chart
Screenshots/recordings
Superset version
4.0.0
Python version
3.9
Node version
16
Browser
Chrome
Additional context
It seems that the export/import functionality doesn’t copy the query_context field. (It becomes null after import)
I believe the query_context became important after this PR: https://github.com/apache/superset/pull/27484/files
Workaround
I noticed that just by opening the imported chart in the superset side updates the query_context and the embed starts working for that chart. We can’t use this workaround as we have hundreds of charts for each of our clients.
Checklist
- 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.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 23 (11 by maintainers)
Sorry, I missed this. Let me take a look, seems like we need to fix the import/export.
To address the issue of “Guest user cannot modify chart payload” for imported charts in Apache Superset 4.0.0, you can automate the update of the
query_contextfor each chart. This can be achieved by either directly interacting with the Superset backend database or using Superset’s REST API to fetch and update charts. Here’s a brief overview of both approaches:Direct Database Manipulation: Write a script that connects to the Superset database, fetches all charts, updates the
query_contextfield in their metadata, and saves the changes back to the database. This method requires direct access to the database and careful handling to avoid data corruption.Using Superset APIs: A safer, albeit potentially slower, method involves using the Superset REST API. You would use the
GET /chart/endpoint to fetch chart configurations, update thequery_contextin each configuration, and then use thePUT /chart/{pk}endpoint to update each chart.Before proceeding with either method, ensure you have a complete backup of your database to prevent data loss. It’s also recommended to test your solution in a development environment before applying it to production.
Here’s a simplified example of how you might use Python to update chart metadata using Superset’s API:
This script is a basic example and will need to be adjusted based on your specific requirements, including authentication and the exact structure of the
updated_config.Details
Sources
About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
To continue the conversation, mention @dosu.
We’ve got a commit on our fork to fix the imports to include the query context. Commit is here: https://github.com/lindenh/superset/commit/eee9b8518cddf3471000cb081e1b8ce1e6a6ebef I’m not 100% if this is the best approach all around and I still need to write some tests to open a PR here, but this has worked really well for our org’s deployment structure. Hope this helps someone else.
From my understanding of the problem:
So a fix could be around properly export the charts in the first place and stop removing the query_context when importing.
A temporary workaround is to update the charts using the api, based on the exported query_context. Of course if you are exporting and importing on a different instance, you need to change ids references in the query_context
Workaround: You can open the Chart using Superset Interface, load the data, and then go to your Embedded dashboard and reload it. It should work.
FROM apache/superset:4.0.2-py310We have also faced this issue after upgrading to 4.0.0