sadpandajoe opened a new pull request, #45374:
URL: https://github.com/apache/superset/pull/45374

   ### SUMMARY
   Fixes "Run in SQL Lab" (and the other "open in SQL Lab" actions) for charts 
that were created with **Create Chart** in SQL Lab. Those charts use a virtual 
`query` datasource whose key is `<query id>__query`. When SQL Lab was opened 
from Explore with that key, `popDatasourceQuery` split off the numeric prefix 
and requested it as a **dataset** id, so users saw "The datasource couldn't be 
loaded". If a dataset with the same numeric id happened to exist, SQL Lab 
silently opened an editor on that unrelated dataset's database and schema 
instead.
   
   ### Root Cause
   `popDatasourceQuery` assumed every datasource key is `<dataset id>__table` 
and discarded the type suffix (`datasourceKey.split('__')[0]`, then `GET 
/api/v1/dataset/{id}`). The earlier type-aware lookup 
(`/fetch_datasource_metadata?datasourceKey=<full key>`) was replaced by this 
dataset-only lookup in #22102. All four entry points (Run in SQL Lab in the 
Explore menu, View in SQL Lab in the datasource menu, Open in SQL Lab in the 
query preview, and View in SQL Lab in the View query modal) pass the full typed 
key to this single consumer.
   
   ### Fix
   In `popDatasourceQuery`, keys of type `query` are now resolved through the 
existing `fetch_datasource_metadata` endpoint with the full key. The editor 
opens with the query's name, database, catalog and schema and the SQL passed 
from Explore (falling back to the stored SQL of the query when none is passed). 
`autorun` stays `false`. If the lookup fails, the existing "The datasource 
couldn't be loaded" toast is shown and no editor is opened. The `table` path is 
unchanged.
   
   No backend, API, schema or dependency changes.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   UI evidence is attached below once verified.
   
   Before: ⋯ → **Run in SQL Lab** from a chart created via SQL Lab's **Create 
Chart** shows the toast "The datasource couldn't be loaded" and stays in 
Explore.
   After: it opens SQL Lab with a new tab on the original query's database and 
schema, with the chart's SQL.
   
   ### TESTING INSTRUCTIONS
   Automated: `cd superset-frontend && npx jest 
src/SqlLab/actions/sqlLab.test.ts -t popDatasourceQuery` (new tests: the 
`query` key is not looked up as a dataset; the exact 
`/fetch_datasource_metadata?datasourceKey=...` request; editor 
database/catalog/schema and SQL precedence; stored-SQL fallback; failure shows 
the toast and opens no editor; the `table` key behavior is unchanged). Before 
the fix 5 of these tests fail.
   
   Manual:
   1. In SQL Lab, run a query against any database and click **Create Chart**.
   2. In Explore, open the ⋯ menu and click **Run in SQL Lab**.
   3. SQL Lab opens a new tab on the query's database and schema containing the 
SQL, without an error toast.
   4. Optionally, if a dataset exists whose id equals the SQL Lab query id, 
confirm the tab still uses the query's database and schema, not the dataset's.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [x] 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
   - [ ] 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]

Reply via email to