Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error when creating a chart from a saved query via API call #23189

Closed
3 tasks done
popescu-af opened this issue Feb 24, 2023 · 4 comments
Closed
3 tasks done

Fatal error when creating a chart from a saved query via API call #23189

popescu-af opened this issue Feb 24, 2023 · 4 comments
Labels
#bug Bug report

Comments

@popescu-af
Copy link

popescu-af commented Feb 24, 2023

SavedQuery class seems to not have a name property, unlike other data sources.
Create chart workflow seems to expect that property on all data source types.

How to reproduce the bug

Assuming a database connection is available. I am using a BigQuery connection, but it's irrelevant to the issue.

  1. Create a saved query request JSON (make sure to use the right database ID)
$ cat saved_query.json
{
    "db_id": 3,
    "label": "saved_query",
    "schema": "public",
    "sql": "SELECT 1"
}
  1. Create the saved query
$ curl http://localhost:8088/api/v1/saved_query/ \
    -H "Content-Type: application/json" \
    -H "Cookie: session=..." \
    -H "X-CSRFToken: ..." \
    -d@saved_query.json
{"id":1,"result":{"db_id":3,"description":null,"label":"saved_query","schema":"public","sql":"SELECT 1","template_parameters":null}}
  1. Create a chart payload JSON (make sure to use the right datasource ID)
$ cat chart.json
{
    "datasource_id": 1,
    "datasource_type": "saved_query",
    "slice_name": "some_name",
    "viz_type": "table"
}
  1. Create the chart
$ curl http://localhost:8088/api/v1/chart/ \
    -H "Content-Type: application/json" \
    -H "Cookie: session=..." \
    -H "X-CSRFToken: ..." \
    -d@chart.json
{"message":"Fatal error"}

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:

superset_app          | 2023-02-24 12:15:23,974:ERROR:flask_appbuilder.api:'SavedQuery' object has no attribute 'name'
superset_app          | Traceback (most recent call last):
superset_app          |   File "/usr/local/lib/python3.8/site-packages/flask_appbuilder/api/__init__.py", line 110, in wraps
superset_app          |     return f(self, *args, **kwargs)
superset_app          |   File "/app/superset/views/base_api.py", line 124, in wraps
superset_app          |     raise ex
superset_app          |   File "/app/superset/views/base_api.py", line 115, in wraps
superset_app          |     duration, response = time_function(f, self, *args, **kwargs)
superset_app          |   File "/app/superset/utils/core.py", line 1586, in time_function
superset_app          |     response = func(*args, **kwargs)
superset_app          |   File "/app/superset/utils/log.py", line 266, in wrapper
superset_app          |     value = f(*args, **kwargs)
superset_app          |   File "/app/superset/views/base_api.py", line 87, in wraps
superset_app          |     return f(self, *args, **kwargs)
superset_app          |   File "/app/superset/charts/api.py", line 316, in post
superset_app          |     new_model = CreateChartCommand(item).run()
superset_app          |   File "/app/superset/charts/commands/create.py", line 44, in run
superset_app          |     self.validate()
superset_app          |   File "/app/superset/charts/commands/create.py", line 64, in validate
superset_app          |     self._properties["datasource_name"] = datasource.name
superset_app          | AttributeError: 'SavedQuery' object has no attribute 'name'
superset_app          | 172.20.0.1 - - [24/Feb/2023:12:15:23 +0000] "POST /api/v1/chart/ HTTP/1.1" 500 26 "-" "curl/7.81.0"

Screenshots

none

Environment

(please complete the following information):

  • browser type and version: -
  • superset version: master, 2.1.0rc1 (1.5.3 does not support saved query as data source for charts)
  • python version: Python 3.10.6
  • node.js version: -
  • any feature flags active: -

Checklist

Make sure to follow these steps before submitting your issue - thank you!

  • I have checked the superset logs for python stacktraces and included it here as text if there are any.
  • I have reproduced the issue with at least the latest released version of superset.
  • I have checked the issue tracker for the same issue and I haven't found one similar.

Additional context

Ubuntu 22.04, ran locally using docker compose.
I was lazy and used the cookie authentication from the browser, but it shouldn't matter wrt the problem.

@popescu-af popescu-af added the #bug Bug report label Feb 24, 2023
@popescu-af
Copy link
Author

In 2.0.1 I get {"message":{"datasource_id":["Datasource does not exist"]}} even though the saved query exists and has the ID I pass to the create chart call.

@Aqib5wani
Copy link

Hello popescu,

Could you use datasource_type table instead saved_query then it should work properly while creating the chart.

@ShaliniIruvuru
Copy link

Working as Expected.Got the results with the creation of the chart from the saved query.
Screenshots:-
image

@rusackas
Copy link
Member

Agreed, seems to be working as expected for a long while indeed. This is likely fixed by now, and is pretty out of date if not. If people are still encountering this in current versions (3.x) please open a new Issue or a PR to address the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#bug Bug report
Projects
None yet
Development

No branches or pull requests

4 participants