EnxDev commented on code in PR #45374:
URL: https://github.com/apache/superset/pull/45374#discussion_r4297602232


##########
superset-frontend/src/SqlLab/actions/sqlLab.ts:
##########
@@ -1661,7 +1662,29 @@ export function popDatasourceQuery(
 ): SqlLabThunkAction<Promise<unknown>> {
   return function (dispatch: AppDispatch) {
     const QUERY_TEXT = t('Query');
-    const datasetId = datasourceKey.split('__')[0];
+    const [datasetId, datasourceType] = datasourceKey.split('__');
+
+    // The id of a `query` datasource is a SQL Lab query id, not a dataset id.
+    if (datasourceType === DatasourceType.Query) {

Review Comment:
   `semantic_view` charts get Run in SQL Lab and View in SQL Lab too, and 
`5__semantic_view` still falls through to `/api/v1/dataset/5`. That's the same 
id collision this PR fixes, so it can open an unrelated dataset's database.
   
   Worth flipping the guard so only `table` goes to the dataset API and 
anything else either uses this metadata path or shows the toast?



##########
superset-frontend/src/SqlLab/actions/sqlLab.ts:
##########
@@ -1661,7 +1662,29 @@ export function popDatasourceQuery(
 ): SqlLabThunkAction<Promise<unknown>> {
   return function (dispatch: AppDispatch) {
     const QUERY_TEXT = t('Query');
-    const datasetId = datasourceKey.split('__')[0];
+    const [datasetId, datasourceType] = datasourceKey.split('__');
+
+    // The id of a `query` datasource is a SQL Lab query id, not a dataset id.
+    if (datasourceType === DatasourceType.Query) {
+      return SupersetClient.get({
+        endpoint: 
`/fetch_datasource_metadata?datasourceKey=${encodeURIComponent(datasourceKey)}`,
+      })
+        .then(({ json }) =>
+          dispatch(
+            addQueryEditor({
+              name: `${QUERY_TEXT} ${json.name}`,

Review Comment:
   Nit, take it or leave it. `Query.data` returns `tab_name` as `name`, and 
that column is nullable. Queries sent through the API without a tab come back 
with no name, so the editor opens as "Query null".
   
   ```suggestion
                 name: json.name ? `${QUERY_TEXT} ${json.name}` : QUERY_TEXT,
   ```



-- 
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]

Reply via email to