-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
500 'Fatal error' When Creating Dashboard Through Public API #22704
Comments
Working as Expected.Created a dashboard test.js:- async function createDashboard() {
} async function getAuthToken() {
} Output:- [Running] node "/home/shali/AS_202/test.js" [Done] exited with code=0 in 0.306 seconds |
Same issue |
same issue here, same log output as @lekhanhtoan37 EDIT: added test code: package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
const (
supersetURL = "https://subdomain.domain.net"
datasourceName = "someDatasource"
databaseURL = "postgresql://some-username:some-password@some-host:5432/backend"
loginURL = supersetURL + "/api/v1/security/login"
)
type LoginRequest struct {
Password string `json:"password"`
Provider string `json:"provider"`
Refresh bool `json:"refresh"`
Username string `json:"username"`
}
type LoginResponse struct {
AccessToken string `json:"access_token"`
}
type DatabasePayload struct {
Engine string `json:"engine"`
ConfigurationMethod string `json:"configuration_method"`
DatabaseName string `json:"database_name"`
SQLAlchemyURI string `json:"sqlalchemy_uri"`
}
type DashboardPayload struct {
DashboardName string `json:"dashboard_title"`
}
func getAccessToken() (string, error) {
// Prepare payload for authentication
loginPayload := LoginRequest{
Password: "somepassword",
Provider: "db",
Refresh: true,
Username: "do-not-change",
}
payloadBytes, err := json.Marshal(loginPayload)
if err != nil {
return "", err
}
resp, err := http.Post(loginURL, "application/json", bytes.NewBuffer(payloadBytes))
if err != nil {
return "", err
}
defer resp.Body.Close()
var loginResp LoginResponse
if err := json.NewDecoder(resp.Body).Decode(&loginResp); err != nil {
return "", err
}
return loginResp.AccessToken, nil
}
func createDashboard(client *http.Client, token string) {
// Endpoint URL
dashboardURL := supersetURL + "/api/v1/dashboard/"
// Prepare dashboard payload
dashboardPayload := DashboardPayload{
DashboardName: "ashboard",
}
payloadBytes, err := json.Marshal(dashboardPayload)
if err != nil {
fmt.Println("Error marshalling dashboard payload:", err)
return
}
// Create request for the dashboard
req, err := http.NewRequest("POST", dashboardURL, bytes.NewBuffer(payloadBytes))
if err != nil {
fmt.Println("Error creating dashboard request:", err)
return
}
// Set headers
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
// Send request
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending dashboard request:", err)
return
}
defer resp.Body.Close()
// Read and print response
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading dashboard response body:", err)
return
}
fmt.Println("Dashboard Response:", string(body))
}
func main() {
client := &http.Client{}
// Get the access token first
token, err := getAccessToken()
if err != nil {
fmt.Println("Error getting access token:", err)
return
}
// Prepare payload for database connection
payload := DatabasePayload{
ConfigurationMethod: "sqlalchemy_form",
Engine: "postgresql",
DatabaseName: datasourceName,
SQLAlchemyURI: databaseURL,
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
fmt.Println("Error marshalling payload:", err)
return
}
// Create request
req, err := http.NewRequest("POST", supersetURL+"/api/v1/database/", bytes.NewBuffer(payloadBytes))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
// Set headers
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
// Send request
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
// Read and print response
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
fmt.Println("Response:", string(body))
createDashboard(client, token)
} The datasource creation does work, the dashboard creation gives fatal error and: AttributeError: 'AnonymousUserMixin' object has no attribute '_sa_instance_state' |
it works only when using the swagger UI and being logged in, I believe the the token using in |
I was able to get the api working by upgrading to v3.0.1 |
Did you removed the cookies. |
When trying to create a dashboard through the public API I get a response with a 500 status and the body is
The logs show
How to reproduce the bug
docker-compose.yml
superset_config.py
test.js
Expected results
Expect dashboard to get created.
Actual results
Get status code 500. 'Fatal error'
Environment
Checklist
Additional context
The following code produces a 401. Could the user not be getting set from the token? I'm not performing these requests anonymously, so I don't know why I am getting the error
'AnonymousUserMixin' object has no attribute '_sa_instance_state'
.Also it works when I use the swagger ui, but that request sends a cookie not a bearer token.
The text was updated successfully, but these errors were encountered: