You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "Amen-Zelealem (via GitHub)" <gi...@apache.org> on 2025/09/20 09:05:31 UTC
[I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Amen-Zelealem opened a new issue, #35221:
URL: https://github.com/apache/superset/issues/35221
### Bug description
## đ Bug Report
### **Summary**
The Superset API does not support programmatically populating the METRIC field when creating charts, requiring manual drag-and-drop interaction even when metrics are properly defined in the chart payload.
### **Expected Behavior**
When creating a chart via the API with a properly formatted metrics array in the `params` field, the METRIC field should be automatically populated in the Superset UI, eliminating the need for manual drag-and-drop configuration.
### **Actual Behavior**
The METRIC field remains empty in the Superset UI even when the chart payload includes correctly formatted metrics. Users must manually drag metrics from the left panel to the METRIC field, which defeats the purpose of programmatic chart creation.
### **Steps to Reproduce**
1. **Create a dataset** via API:
```bash
POST /api/v1/dataset/
{
"database": 1,
"table_name": "test_table",
"schema": "public"
}
```
2. **Create a chart** with metrics in the payload:
```bash
POST /api/v1/chart/
{
"slice_name": "Test Chart",
"viz_type": "pie",
"datasource_id": 123,
"datasource_type": "table",
"params": "{\"groupby\": [\"status\"], \"metrics\": [\"COUNT(*)\"]}"
}
```
3. **Open the chart** in Superset UI
4. **Observe** that the METRIC field is empty despite `COUNT(*)` being available in the left panel
### **Environment**
- **Superset Version**: Version: 4.1.2
- **Python Version**: 3.12
- **Database**: PostgreSQL
- **Browser**: Chrome
### **Additional Context**
#### **What Works:**
â
Dataset creation via API
â
Chart creation via API
â
Dimension/groupby configuration
â
Chart styling and customization
â
All other chart properties
#### **What Doesn't Work:**
â Automatic METRIC field population
â Programmatic metric configuration
#### **Attempted Solutions:**
1. **Simple string format**: `["COUNT(*)"]`
2. **Object format**: `[{"label": "COUNT(*)", "expressionType": "SIMPLE", "sqlExpression": "COUNT(*)"}]`
3. **Extended object format**: `[{"label": "COUNT(*)", "expressionType": "SIMPLE", "sqlExpression": "COUNT(*)", "id": "COUNT(*)", "metric_name": "COUNT(*)"}]`
4. **Metric endpoints**: All `/metric/`, `/metrics/`, `/metric` endpoints return 404
5. **Immediate metric addition**: Tried adding metrics right after dataset creation
#### **Impact:**
This limitation significantly reduces the value of Superset's API for automated dashboard creation workflows. Users must manually configure metrics for every chart, making it impossible to fully automate dashboard generation.
#### **Proposed Solution:**
The API should accept and properly process metrics in the chart creation payload, automatically populating the METRIC field in the UI. This would enable true programmatic chart creation without manual intervention.
---
**Note**: This issue affects the core functionality of programmatic chart creation and should be prioritized for the next release.
### Screenshots/recordings
_No response_
### Superset version
master / latest-dev
### Python version
3.9
### Node version
16
### Browser
Chrome
### Additional context
_No response_
### 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.
--
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.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
Re: [I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Posted by "msyavuz (via GitHub)" <gi...@apache.org>.
msyavuz commented on issue #35221:
URL: https://github.com/apache/superset/issues/35221#issuecomment-3320228409
Hey, seems the issue is resolved, i am closing it but feel free to reopen
--
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
Re: [I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Posted by "Amen-Zelealem (via GitHub)" <gi...@apache.org>.
Amen-Zelealem commented on issue #35221:
URL: https://github.com/apache/superset/issues/35221#issuecomment-3314885354
Could you provide specific code examples for the PUT request workaround to update charts after creation? What's the exact endpoint and payload format?
--
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
Re: [I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Posted by "youssefmasmoudi168 (via GitHub)" <gi...@apache.org>.
youssefmasmoudi168 commented on issue #35221:
URL: https://github.com/apache/superset/issues/35221#issuecomment-4134720888
I have the same problem is it resolved in some version or is there any better alternative BI Tool to solve this issue.
--
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
Re: [I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Posted by "Amen-Zelealem (via GitHub)" <gi...@apache.org>.
Amen-Zelealem commented on issue #35221:
URL: https://github.com/apache/superset/issues/35221#issuecomment-3314930795
Thank you @dosu for this crucial clarification! This explains exactly what I've been experiencing and provides the definitive answer we needed.
--
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
Re: [I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #35221:
URL: https://github.com/apache/superset/issues/35221#issuecomment-3314831659
<!-- Greeting -->
Hi @Amen-Zelealem! I'm [Dosu](https://go.dosu.dev/dosubot) and Iâm helping the superset team.
<!-- Answer -->
That's correctâdue to a known limitation in Superset's API, metrics can't be programmatically populated in the METRIC field when creating charts. Manual drag-and-drop in the UI is required, even if metrics are included in the API payload. This behavior is confirmed in several issues and discussions, and is caused by the fact that the query context (which includes metrics) is generated by frontend logic when the chart is loaded, not by the backend or API alone ([issue #32966](https://github.com/apache/superset/issues/32966), [discussion #34750](https://github.com/apache/superset/discussions/34750), [discussion #33574](https://github.com/apache/superset/discussions/33574)).
Some users have tried workarounds like sending a PUT request to update the chart or dashboard after creation, using browser automation to trigger the frontend logic, or writing custom backend jobs, but none of these guarantee automatic metric field population in the UI. If you want more technical details or code references for these workarounds, let me know!
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/054a3496-96a8-48a4-9f36-141b93c1caea?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/054a3496-96a8-48a4-9f36-141b93c1caea?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/054a3496-96a8-48a4-9f36-141b93c1caea?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/054a3496-96a8-48a4-9f36-141b93c1caea?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/054a3496-96a8-48a4-9f36-141b93c1caea?feedback_type=hallucination) | [Report đ](https://app.dosu.dev/response-feedback/054a3496-96a8-48a4-9f36-141b93c1caea?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/054a3496-96a8-48a4-9f36-141b93c1caea?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=githu
b) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/35221)
--
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
Re: [I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Posted by "msyavuz (via GitHub)" <gi...@apache.org>.
msyavuz closed issue #35221: API Limitation: Cannot programmatically populate METRIC field in chart creation
URL: https://github.com/apache/superset/issues/35221
--
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
Re: [I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Posted by "Amen-Zelealem (via GitHub)" <gi...@apache.org>.
Amen-Zelealem commented on issue #35221:
URL: https://github.com/apache/superset/issues/35221#issuecomment-3314830953
Because of this issue the user manually need to drag the metrics and create the chart.
--
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
Re: [I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #35221:
URL: https://github.com/apache/superset/issues/35221#issuecomment-3314928976
<!-- Answer -->
This is expected behavior in current Superset versions. When you update or create a chart via the API (including with a PUT request), the chart's query contextâwhich is required for the chart to load in the UIâis not generated by the backend. Instead, it's built by frontend JavaScript logic when you open and save the chart in the UI. If you never open and save the chart in the UI, the chart may become inaccessible (404 or 400 errors) because the backend doesn't have the necessary query context to serve it. This is a known limitation and not a permissions issue; permission problems would typically result in a 403 error, not 404Â ([details](https://github.com/apache/superset/issues/33615)).
To fix this, you need to manually open and save each chart in the UI, or use browser automation to do so programmatically. There is currently no supported backend or API-only workaround to generate the query context for charts.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/df799611-b08e-44a6-a589-b582b1dc3414?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/df799611-b08e-44a6-a589-b582b1dc3414?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/df799611-b08e-44a6-a589-b582b1dc3414?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/df799611-b08e-44a6-a589-b582b1dc3414?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/df799611-b08e-44a6-a589-b582b1dc3414?feedback_type=hallucination) | [Report đ](https://app.dosu.dev/response-feedback/df799611-b08e-44a6-a589-b582b1dc3414?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/df799611-b08e-44a6-a589-b582b1dc3414?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=githu
b) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/35221)
--
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
Re: [I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #35221:
URL: https://github.com/apache/superset/issues/35221#issuecomment-3314887077
<!-- Answer -->
You can update a chart in Superset using a PUT request to the endpoint `/api/v1/chart/<chart_id>`. The payload must conform to the `ChartPutSchema`, where the `params` field is a JSON string that includes your chart configuration, such as metrics and groupby. For example:
```json
PUT /api/v1/chart/123
Content-Type: application/json
{
"slice_name": "Test Chart",
"viz_type": "pie",
"datasource_id": 123,
"datasource_type": "table",
"params": "{\"groupby\": [\"status\"], \"metrics\": [\"COUNT(*)\"]}"
}
```
You can also use more complex metric objects in the `metrics` array, following the ad-hoc metric schema (e.g., with `expressionType`, `label`, `sqlExpression`). The backend simply stores this string; the frontend interprets it when rendering the chart. Note that even after a successful update, the METRIC field in the UI may still require manual interaction due to frontend logicâthis is a known limitation [cite](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/charts/api.py) [cite](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/charts/schemas.py) [cite](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/tests/integration_tests/charts/api_tests.py).
If you want to update other fields (like dashboards, owners, etc.), include them in the payload as needed. The key part for metrics is always the `params` JSON string.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/29de4279-18bf-4de7-9cc7-6ba3bce130bc?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/29de4279-18bf-4de7-9cc7-6ba3bce130bc?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/29de4279-18bf-4de7-9cc7-6ba3bce130bc?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/29de4279-18bf-4de7-9cc7-6ba3bce130bc?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/29de4279-18bf-4de7-9cc7-6ba3bce130bc?feedback_type=hallucination) | [Report đ](https://app.dosu.dev/response-feedback/29de4279-18bf-4de7-9cc7-6ba3bce130bc?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/29de4279-18bf-4de7-9cc7-6ba3bce130bc?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=githu
b) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/35221)
--
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
Re: [I] API Limitation: Cannot programmatically populate METRIC field in chart creation [superset]
Posted by "Amen-Zelealem (via GitHub)" <gi...@apache.org>.
Amen-Zelealem commented on issue #35221:
URL: https://github.com/apache/superset/issues/35221#issuecomment-3314928341
The PUT request workaround works (200 OK), but charts become immediately inaccessible (404) after creation. Is this expected behavior, or is there a permissions/access issue?
The query context (which includes metrics) is generated by frontend logic when the chart is loaded, not by the backend or API alone
--
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