MDeadman opened a new pull request, #38638: URL: https://github.com/apache/superset/pull/38638
### SUMMARY Addresses: https://github.com/apache/superset/discussions/38133 This PR adds a feature to the /api/v1/chart/{id}/data GET endpoint, to enable you to specify an additional parameter: filters_dashboard_id. When you pass in the ID of a dashboard to this parameter, it will apply all the filters on the dashboard which are applicable to this chart. It will ensure that: * You have access to the dashboard * The chart exists on the dashboard Filters will only be applied to the chart: * If the chart is in scope for the given filter * If the filter has a default value, mirroring the front-end behaviour when loading up a dashbaord * **IMPORTANT CAVEAT**: The filter is NOT using the "Select first filter value by default" option. This option requires a prequery to get the first item in a column to use for the default value. This would require a re-implimentation of the logic used to power that feature, and would create an inconsistancy in results when using the QUERY type in the request, as we would not want to execute that pre-query with the QUERY setting. The downside of this approach is we now have an inconsistancy between the front-end behaviour and the API endpoint behaviour here, but after discussing with Beto and Kamil we figured this was the better approach. The returned result will reflect the applied filters, and include an additional dashboard_filters object, which will show which filters exist on the dashboard, and which were applied to your request. If the user is using the "defaultToFirstItem" it will return a status of "not_applied_uses_default_to_first_item_prequery" to make it very clear to the end user a given filter was not applied because of this option. Column info is also included to help users understand the impact this filter had on their query. Example: ` "dashboard_filters": { "filters": [ { "id": "NATIVE_FILTER-HM7ype0AH9IJEHcJ4vyhZ", "name": "Genre test", "status": "applied", "column": "genre" } ] } ` ### TESTING INSTRUCTIONS Spin up superset and create a filter on a dashboard. Make sure it is scoped to hit a chart you want to test. Hit the chart endpoint with filters_dashboard_id = the id of your dashboard with filters. I.E. GET http://localhost:8088/api/v1/chart/89/data/?filters_dashboard_id=8 Check that query text and results have updated, and that the dashboard_filters include all filters. Remove the scoping from the chart in the filter settings and run again. Make sure the filter has not been applied. Also test removing the default value, and setting "Select first filter value by default" to true and ensuring both show in dashboard filters, but are not applied. Run the tests: ` pytest tests/integration_tests/charts/data/api_tests.py pytest tests/unit_tests/charts/test_dashboard_filter_context.py ` ### ADDITIONAL INFORMATION - [X] Has associated issue: [#38133](https://github.com/apache/superset/discussions/38133) - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351)) - [ ] Migration is atomic, supports rollback & is backwards-compatible - [ ] Confirm DB migration upgrade and downgrade tested - [ ] Runtime estimates and downtime expectations provided - [X] Introduces new feature or API - [ ] Removes existing feature or API -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
