You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/03/22 20:20:45 UTC
[GitHub] [superset] timwil opened a new issue #13733: Unable to create charts using REST api
timwil opened a new issue #13733:
URL: https://github.com/apache/superset/issues/13733
Hello
I am using apache superset in my platform that I am building at the moment. One of the features of this platform is to create basic visualizations on a given dataset. To do this I am working with the REST api of superset (as documented here: https://superset.apache.org/docs/rest-api). Currently I am trying to create charts using this api but I have stumbled upon a problem.
The problem is that upon calling the api, a response is send back with status code 500 and the message "fatal error"

I have provide a code snippet that makes the POST request to create a chart. At first the access token is retrieved (which seems to work). This token gets added to the headers of the actually request. The payload is hardcoded for now just to see if the chart is actually created. I should note that it is possible to manually login in superset and using swagger/v1, to create a chart using the payload used in the given code snippet.
code snippet:
...
@router.post("/chart/")
async def create_chart(datasource_id: int, viz_type: str, client: AsyncClient = Depends(superset_connection.get_superset_client)):
dataset = await get_dataset(datasource_id, client)
login = {
"password": "admin",
"provider": "db",
"refresh": True,
"username": "admin"
}
headers = {
'Content-Type': 'application/json'
}
response = await client.post(url='/security/login', headers = headers, json = login)
token = response.json()['access_token']
headers = {
'accept': 'application/json',
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
}
# payload for POST request
payload = {
"cache_timeout": 0,
"dashboards": [],
"datasource_id": 9,
"datasource_name": "ob201",
"datasource_type": "table",
"description": "lorem ipsum",
"owners": [],
"params": "",
"slice_name": "test_slice",
"viz_type": "table"
}
response = await client.post(url="/chart", json = payload, headers = headers)
# verify if request has succeeded
if(response.status_code != 200):
raise HTTPException(status_code=response.status_code, detail=response.json())
return response
...
Stack trace:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/api/__init__.py", line 84, in wraps
return f(self, *args, **kwargs)
File "/app/superset/views/base_api.py", line 80, in wraps
duration, response = time_function(f, self, *args, **kwargs)
File "/app/superset/utils/core.py", line 1400, in time_function
response = func(*args, **kwargs)
File "/app/superset/utils/log.py", line 217, in wrapper
value = f(*args, **kwargs)
File "/app/superset/charts/api.py", line 274, in post
new_model = CreateChartCommand(g.user, item).run()
File "/app/superset/charts/commands/create.py", line 46, in run
chart = ChartDAO.create(self._properties)
File "/app/superset/dao/base.py", line 104, in create
db.session.add(model)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/scoping.py", line 163, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/session.py", line 2019, in add
self._save_or_update_state(state)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/session.py", line 2036, in _save_or_update_state
"save-update", state, halt_on=self._contains_state
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/mapper.py", line 3104, in cascade_iterator
halt_on,
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/relationships.py", line 1937, in cascade_iterator
tuples = state.manager[self.key].impl.get_all_pending(state, dict_)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/attributes.py", line 1148, in get_all_pending
for c in current
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/attributes.py", line 1148, in <listcomp>
for c in current
File "/usr/local/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'AnonymousUserMixin' object has no attribute '_sa_instance_state'
10.99.49.186 - - [22/Mar/2021:19:45:49 +0000] "POST /api/v1/chart/ HTTP/1.1" 500 26 "-" "python-httpx/0.17.1"
I tried to search to related problems but I can't seem to find something similar. What are the possible causes of this? I was thinking that I did something wrong in configuring superset but I can't seem to put my finger on it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] anilvpatel21 edited a comment on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
anilvpatel21 edited a comment on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-895061530
@nytai Thanks. Removing `AUTH_ROLE_PUBLIC = 'Gamma'` works.
Generating JWT Token for the admin role.
But do we need this role permission for the API's as we are generating a JWT token for a particular user under some role. So if that role has a permission to access an api it should work.
Interesting:
```
PUBLIC_ROLE_LIKE = 'Gamma' did not work.
but PUBLIC_ROLE_LIKE = 'Public' did work
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] anilvpatel21 commented on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
anilvpatel21 commented on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-895061530
@nytai I m getting token for Admin role. I tried removing `AUTH_ROLE_PUBLIC = 'Gamma' and PUBLIC_ROLE_LIKE = 'Gamma'` and tried. Getting `401 unauthorised error.` Even I am passing JWT bearer token.
Did `superset init` and then tried, no luck.
I am making a API call from the node server, so I do not have any cookies. Do we need session cookies or anything else along with JWT token.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] anilvpatel21 edited a comment on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
anilvpatel21 edited a comment on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-894846072
@dpgaspar Hi, Getting same error
`AttributeError: 'AnonymousUserMixin' object has no attribute '_sa_instance_state'`
I am passing a JWT Auth token of user which also has Admin as well as Gamma role.
AUTH_ROLE_PUBLIC = 'Gamma'
PUBLIC_ROLE_LIKE = 'Gamma'
and in the Gamma role, i have can read on & can write on permission of ReportSchedule.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] nytai commented on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
nytai commented on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-894859594
The CSRF token header is `X-CSRFToken`. Not sure why you're getting that error as as you're logging in as a user. Which role does the user have you're logging into `/api/v1/security/login`? I would remove the `AUTH_ROLE_PUBLIC = 'Gamma'` and
`PUBLIC_ROLE_LIKE = 'Gamma'` and try again.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] anilvpatel21 edited a comment on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
anilvpatel21 edited a comment on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-894846072
@dpgaspar Hi, Getting same error
`AttributeError: 'AnonymousUserMixin' object has no attribute '_sa_instance_state'`
I am passing a JWT Auth token of user which also has Admin as well as Gamma role.
````
headers: {
'CSRF-TOKEN': //token obtain from '/api/v1/security/csrf_token' endpoint
'Authorization': 'Bearer ' + //access_token obtain '/api/v1/security/login' endpoint
}
````
AUTH_ROLE_PUBLIC = 'Gamma'
PUBLIC_ROLE_LIKE = 'Gamma'
and in the Gamma role, i have can read on & can write on permission of ReportSchedule.
Superset 1.1.0
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] anilvpatel21 edited a comment on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
anilvpatel21 edited a comment on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-895061530
@nytai I m getting token for Admin role. I tried removing `AUTH_ROLE_PUBLIC = 'Gamma' and PUBLIC_ROLE_LIKE = 'Gamma'` and tried. Getting `401 unauthorised error.` Even I am passing JWT bearer token.
Did `superset init` and then tried, no luck.
I am making a API call from the node server, so I do not have any cookies. Do we need session cookies or anything else along with JWT token in the request header.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] nytai commented on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
nytai commented on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-894859752
Not sure why you're getting `AnonymousUserMixin` as the user should not be anonymous
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] dpgaspar commented on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
dpgaspar commented on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-813374425
@timwil
The auth token should correctly set the user, using the default configuration to invoke the API programatically you have to send the CSRF token also. `AnonymousUserMixin` error, seems that chart POST is allowed by an anonymous user, do you have `PUBLIC_ROLE_LIKE` set?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] WingCode commented on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
WingCode commented on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-917684833
For now, did a workaround mentioned in https://github.com/apache/superset/issues/16398 to login into the website and obtain the auth cookie & proceeding to create the dashboard afterwards.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] WingCode commented on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
WingCode commented on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-917634511
@anilvpatel21 I am facing this same issue while creating dashboard. Tried the fixes above to test it but unfortunately didn't work. Could you paste your superset_config.py over here? If you can include the complete sample code that will be also great!
Superset version: 1.3
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] WingCode edited a comment on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
WingCode edited a comment on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-917684833
For now, did a workaround mentioned in https://github.com/apache/superset/issues/16398 to login into the website and obtain the auth token from cookie & proceeding to create the dashboard afterwards.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] inteon commented on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
inteon commented on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-812006942
+1
I'm also encountering this problem.
@junlincc Not sure this is a question: @nytai Is this "Fatal error" due to a configuration error or should this issue be labeled as "bug"?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] anilvpatel21 commented on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
anilvpatel21 commented on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-894846072
@dpgaspar
`Getting same error. AttributeError: 'AnonymousUserMixin' object has no attribute '_sa_instance_state'`
I am passing a JWT Auth token of user which also has Admin as well as Gamma role.
AUTH_ROLE_PUBLIC = 'Gamma'
PUBLIC_ROLE_LIKE = 'Gamma'
and in the Gamma role, i have can read on & can write on permission of ReportSchedule.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] nytai commented on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
nytai commented on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-804371024
@dpgaspar does the auth token correctly set the current user?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] anilvpatel21 edited a comment on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
anilvpatel21 edited a comment on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-895061530
@nytai Thanks. Removing `AUTH_ROLE_PUBLIC = 'Gamma'` works.
Generating JWT Token for the admin role.
But do we need this role permission for the API's as we are generating a JWT token for a particular user under some role. So if that role has a permission to access an api it should work.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] anilvpatel21 edited a comment on issue #13733: Unable to create charts using REST api
Posted by GitBox <gi...@apache.org>.
anilvpatel21 edited a comment on issue #13733:
URL: https://github.com/apache/superset/issues/13733#issuecomment-894846072
@dpgaspar Hi, Getting same error
`AttributeError: 'AnonymousUserMixin' object has no attribute '_sa_instance_state'`
I am passing a JWT Auth token of user which also has Admin as well as Gamma role.
````
headers: {
'CSRF-TOKEN': //token obtain from '/api/v1/security/csrf_token' endpoint
'Authorization': 'Bearer ' + //access_token obtain '/api/v1/security/login' endpoint
}
````
AUTH_ROLE_PUBLIC = 'Gamma'
PUBLIC_ROLE_LIKE = 'Gamma'
and in the Gamma role, i have can read on & can write on permission of ReportSchedule.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org