dpgaspar commented on a change in pull request #13523:
URL: https://github.com/apache/superset/pull/13523#discussion_r591671198
##########
File path: superset/dashboards/dao.py
##########
@@ -57,6 +58,29 @@ def get_by_id_or_slug(id_or_slug: str) -> Dashboard:
raise DashboardNotFoundError()
return dashboard
+ @staticmethod
+ def get_datasets_for_dashboard(id_or_slug: str) -> Dict[str, Any]:
+ query = (
+ db.session.query(Dashboard)
+ .filter(id_or_slug_filter(id_or_slug))
+ .outerjoin(Slice, Dashboard.slices)
+ .outerjoin(Slice.table)
+ )
+ # Apply dashboard base filters
+ query = DashboardFilter("id", SQLAInterface(Dashboard,
db.session)).apply(
+ query, None
+ )
+ dashboard = query.one_or_none()
+ if not dashboard:
+ raise DashboardNotFoundError()
Review comment:
Feels kind of strange that a `DAO` raises a `Command` Exception
##########
File path: superset/dashboards/api.py
##########
@@ -252,6 +253,54 @@ def get(self, id_or_slug: str) -> Response:
except DashboardNotFoundError:
return self.response_404()
+ @expose("/<id_or_slug>/datasets", methods=["GET"])
+ @protect()
+ @safe
+ @statsd_metrics
+ @event_logger.log_this_with_context(
+ action=lambda self, *args, **kwargs:
f"{self.__class__.__name__}.get_datasets",
+ log_to_statsd=False,
+ )
+ def get_datasets(self, id_or_slug: str) -> Response:
+ """Gets a dashboard's datasets
+ ---
+ get:
+ description: >-
+ Returns a map of a dashboard's datasets, keyed by dataset
Uid.
+ Each dataset includes only the information necessary to
render
+ the dashboard's charts.
+ parameters:
+ - in: path
+ schema:
+ type: string
+ name: id_or_slug
+ description: Either the id of the dashboard, or its slug
+ responses:
+ 200:
+ description: Dashboard dataset definitions
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ result:
+ type: object
Review comment:
Better to declare a marshmallow schema and reference it here
----------------------------------------------------------------
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]