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

   ### SUMMARY
   
   The table selector in SQL Lab fails to load tables after the user selects a 
database and schema. Two interrelated issues cause this:
   
   **1. Stale `database` prop in `TableSelector`**
   
   In SQL Lab, the `database` prop passed to `TableSelector` is `null` during 
initial renders because `useDatabaseSelector` relies on a multi-step Redux 
state propagation chain (`useEffect` -> dispatch -> `useEffect`). This means 
`database?.id` passed to `useTables` is `undefined`, so the tables query never 
fires.
   
   **Fix:** Track `currentDbId` in local component state, setting it 
immediately from the `internalDbChange` callback instead of waiting for the 
Redux roundtrip to propagate back through the `database` prop.
   
   **2. Redundant schema validation in `useTables`**
   
   The `useTables` hook called `useSchemas` internally to validate that the 
selected schema exists in the schema list before enabling the tables query. 
This was redundant -- the schema already comes from a validated dropdown in 
`DatabaseSelector` -- and introduced a race condition where RTK Query's 
`currentData` could be `undefined` on the first render cycle, blocking the 
tables query even with a valid `dbId`.
   
   **Fix:** Simplify the `enabled` guard to `Boolean(dbId && schema)` and 
remove the internal `useSchemas` dependency.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   **Before:** After selecting a database and schema in SQL Lab, the table 
dropdown shows empty / "No data".
   
   **After:** Tables load correctly after selecting database and schema.
   
   ### TESTING INSTRUCTIONS
   
   1. Open SQL Lab
   2. Select a database from the database dropdown
   3. Select a schema from the schema dropdown
   4. Verify that the table dropdown populates with tables from the selected 
schema
   5. Switch databases and repeat -- tables should load for the new 
database/schema combination
   6. Verify that with no database selected, the tables query does not fire
   7. Verify that with no schema selected, the tables query does not fire
   
   ### 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