Open imtiaznizami opened 1 month ago
Hello, @imtiaznizami! I'm here to help you with any bugs, questions, or contributions you have for the repository. Let me know how I can assist you!
To resolve the fatal error when trying to create a chart from a saved_query
via an API call in Superset version 4.0.2 using Docker Compose, you should apply the fix provided in the pull request #27644. This fix provides more inclusive error handling for saved queries.
Here is the relevant change from the pull request:
- [#27644](https://github.com/apache/superset/pull/27644) fix: Provide more inclusive error handling for saved queries (@john-bodley)
Ensure that your Superset instance includes this fix by updating to the latest version that includes this pull request or manually applying the changes from the pull request to your local instance [1].
Backup Your Data: Before performing any upgrade, ensure you have a backup of your current Superset data and configuration.
Update Superset:
pip install apache-superset==4.0.0
docker-compose.yml
to use the new version:
version: '3.1'
services:
superset:
image: apache/superset:4.0.0
...
Then, pull the new image and restart the services:
docker-compose pull
docker-compose up -d
Run Database Migrations: After updating the Superset version, you need to run the database migrations to ensure your database schema is up-to-date:
superset db upgrade
Restart Superset: Finally, restart the Superset service to apply the changes:
superset run
By following these steps, you will update Superset to version 4.0.0, which includes the fix from pull request #27644 [1].
To continue talking to Dosu, mention @dosu.
@dosu As mentioned in my original post, I am using 4.0.2 which is more recent than 4.0.0 suggested by you. Also, the issue you referenced has 4.0.2 label as well.
To resolve the fatal error when trying to create a chart from a saved_query
via an API call in Superset version 4.0.2, you should use datasource_type
as table
instead of saved_query
. This workaround has been suggested in a similar issue and should help you avoid the error [1].
Here is the modified curl command for creating the chart:
curl --location 'http://localhost:8088/api/v1/chart/' \
--header 'Authorization: Bearer eyJ...' \
--header 'X-CSRFToken: ImQ...' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Cookie: .eJ...' \
--data '{
"datasource_id": 11,
"datasource_type": "table",
"slice_name": "some_name",
"viz_type": "table"
}'
This should help you create the chart successfully.
To continue talking to Dosu, mention @dosu.
@dosu
The data-source table
should have completely different set of IDs than data-source saved_queries
.
However, I tried your suggestion, and the chart was created with an entirely different set of columns (which compliments what I wrote above).
To resolve the issue of creating a chart from a saved_query
via an API call in Superset version 4.0.2, you need to ensure that the backend correctly handles saved_query
objects. The error you're encountering ('SavedQuery' object has no attribute 'name'
) indicates that the SavedQuery
object is missing the name
attribute, which is expected by the CreateChartCommand
.
Here are the steps to modify the backend to support saved_query
:
Modify the CreateChartCommand
to handle saved_query
:
Update the validate
method in CreateChartCommand
to correctly handle saved_query
objects. Specifically, you need to extract the necessary information from the SavedQuery
object.
def validate(self) -> None:
exceptions = []
datasource_type = self._properties["datasource_type"]
datasource_id = self._properties["datasource_id"]
dashboard_ids = self._properties.get("dashboards", [])
owner_ids: Optional[list[int]] = self._properties.get("owners")
# Validate/Populate datasource
try:
datasource = get_datasource_by_id(datasource_id, datasource_type)
if datasource_type == "saved_query":
self._properties["datasource_name"] = datasource.label
else:
self._properties["datasource_name"] = datasource.name
except ValidationError as ex:
exceptions.append(ex)
# Validate/Populate dashboards
dashboards = DashboardDAO.find_by_ids(dashboard_ids)
if len(dashboards) != len(dashboard_ids):
exceptions.append(DashboardsNotFoundValidationError())
for dash in dashboards:
if not security_manager.is_owner(dash):
raise DashboardsForbiddenError()
self._properties["dashboards"] = dashboards
try:
owners = self.populate_owners(owner_ids)
self._properties["owners"] = owners
except ValidationError as ex:
exceptions.append(ex)
if exceptions:
raise ChartInvalidError(exceptions=exceptions)
Ensure get_datasource_by_id
supports saved_query
:
The get_datasource_by_id
function already supports saved_query
as a datasource type, so no changes are needed here [1].
Update the frontend if necessary:
Ensure that the frontend correctly handles the saved_query
type when creating charts. This involves making sure that the fetchSlices
function and parseResult
function correctly process saved_query
objects [2].
By making these changes, you should be able to create charts from saved_query
objects without encountering the fatal error.
To continue talking to Dosu, mention @dosu.
@dosu This did not work. I am getting the same error. I think the error is happening at SQLAlchemy level.
Bug description
This is a repeat of #23189. I am unable to create a chart using
saved_query
following the superset API. It responds withFatal error
instead. (superset version 4.0.2 using docker compose)How to reproduce the bug
2
and a table namedcar
)This gives back
This gives back
Expected results Curl command to complete successfully with the creation of the chart from the saved query.
Actual results Curl result is
{"message" : "Fatal error"}
superset app stacktrace:
Also note that in #23189 the answer by ShaliniIruvuru (answer) mentions
query
instead ofsaved_query
in the chart creation JSON (which should be a different object).Screenshots/recordings
No response
Superset version
4.0.2
Python version
I don't know
Node version
I don't know
Browser
Chrome
Additional context
Used the following command to create superset container:
Checklist