hf-13 opened a new issue, #41245:
URL: https://github.com/apache/superset/issues/41245

   ### Bug description
   
   ### Superset version
     6.1.0
   
   ### What's the issue?
   
   When SQL Lab initializes, it fetches the database list via:
   
   GET 
/api/v1/database/?q=(filters:!((col:database_name,opr:neq,value:examples)))
   
   No `page_size` is specified, so FAB defaults to **20 results**. The response 
is dispatched as `SET_DATABASES`, populating the Redux `databases` map with 
only those 20 entries (keyed by integer `id`).
   
   When a user's saved tab has a `database_id` that doesn't appear in the first 
20 results, `databases[dbId]` is `undefined` → the frontend evaluates `F = 
isEmpty(databases[dbId])` as `true` → the yellow warning
   banner appears:
   
   > **The database that was used to generate this query could not be found**
   > Choose one of the available databases on the left panel.
   
   The database exists, permissions are correct, and the tab state in the 
backend is valid. This is a pure frontend state population problem. Reloading 
the page sometimes resolves it (timing-dependent). Clicking
   the database in the left panel always resolves it (that search uses 
`page_size=1000` and correctly finds the database).
   
   ### Steps to reproduce
   
   1. Have a Superset instance with **more than 20 databases**
   2. Ensure a user has a saved SQL Lab tab whose `database_id` is not among 
the first 20 results of `GET /api/v1/database/` (default sort)
   3. Open SQL Lab
   4. Observe the yellow "database not found" banner on that tab despite the 
database being visible and selectable in the left panel
   
   ### Expected behavior
   
   SQL Lab loads without the "database not found" error. All saved tabs display 
correctly regardless of how many databases exist.
   
   ### Actual behavior
   
   Any user whose saved tab references a database outside the first 20 API 
results sees the error on every fresh SQL Lab load.
   
   ### Root cause
   
   `GET /api/v1/database/` without an explicit `page_size` returns FAB's 
default of 20 rows. The SQL Lab init code does not request a larger page size 
or paginate through results. The Redux `databases` map is
   therefore incomplete.
   
   Relevant frontend code (SQL Lab entry bundle, `SET_DATABASES` reducer):
   ```js
   r.databases.forEach(t => { e[t.id] = { ...t, extra_json: JSON.parse(t.extra 
|| "") } })
   
   Relevant error condition:
   const F = useMemo(() => !c || isEmpty(c), [c])  // c = databases[dbId || ""]
   // F === true when dbId not in the 20-entry Redux map → shows error banner
   
   Workaround
   
   Patch DatabaseRestApi.page_size at app startup via FLASK_APP_MUTATOR:
   
   def FLASK_APP_MUTATOR(app):
       from superset.databases.api import DatabaseRestApi
       DatabaseRestApi.page_size = 100000
   
   This causes the unpaginated init call to return all databases. 
DatabaseRestApi.max_page_size is already -1 (unlimited), so no server-side cap 
blocks this.
   
   Proposed fix
   
   The correct fix is in the frontend. The SQL Lab init fetch should either:
   
   Option A — explicitly request all databases:
   // in the SQL Lab init fetch
   GET /api/v1/database/?q=(page_size:100000,filters:!(...))
   
   Option B — defer tab rendering until SET_DATABASES is fully populated, then 
fall back to a targeted fetch for any dbId still missing from the map.
   
   Option B is more robust for very large installations but requires more 
frontend work. Option A is a one-line fix.
   
   Environment
   
   - Superset 6.1.0
   - ~885 databases in the instance
   - FAB default page_size: 20
   - DatabaseRestApi.max_page_size: -1 (unlimited)
   
   
   ### Screenshots/recordings
   
   _No response_
   
   ### Superset version
   
   master / latest-dev
   
   ### Python version
   
   3.9
   
   ### Node version
   
   16
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   ### Superset version
   6.1.0
   
   ### What's the issue?
   
   When SQL Lab initializes, it fetches the database list via:
   GET 
/api/v1/database/?q=(filters:!((col:database_name,opr:neq,value:examples)))
   
   No `page_size` is specified, so FAB defaults to **20 results**. The response 
is dispatched as `SET_DATABASES`, populating the Redux `databases` map with 
only those 20 entries (keyed by integer `id`).
   
   When a user's saved tab has a `database_id` that doesn't appear in the first 
20 results, `databases[dbId]` is `undefined` -> the frontend evaluates `F = 
isEmpty(databases[dbId])` as `true` -> the yellow warning banner appears:
   
   > **The database that was used to generate this query could not be found**
   > Choose one of the available databases on the left panel.
   
   The database exists, permissions are correct, and the tab state in the 
backend is valid. This is a pure frontend state population problem. Reloading 
the page sometimes resolves it (timing-dependent). Clicking the database in the 
left panel always resolves it (that search uses `page_size=1000` and correctly 
finds the database).
   
   ## Steps to reproduce
   
   1. Have a Superset instance with **more than 20 databases**
   2. Ensure a user has a saved SQL Lab tab whose `database_id` is not among 
the first 20 results of `GET /api/v1/database/` (default sort)
   3. Open SQL Lab
   4. Observe the yellow "database not found" banner on that tab despite the 
database being visible and selectable in the left panel
   
   ### Expected behavior
   
   SQL Lab loads without the "database not found" error. All saved tabs display 
correctly regardless of how many databases exist.
   
   ### Actual behavior
   Any user whose saved tab references a database outside the first 20 API 
results sees the error on every fresh SQL Lab load.
   
   ### Root cause
   `GET /api/v1/database/` without an explicit `page_size` returns FAB's 
default of 20 rows. The SQL Lab init code does not request a larger page size 
or paginate through results. The Redux `databases` map is
     therefore incomplete.
   
   Mainly - SQL Lab entry bundle, `SET_DATABASES` reducer.
   
   ### Workaround
   Patch DatabaseRestApi.page_size at app startup via FLASK_APP_MUTATOR:
   
   ```python
   def FLASK_APP_MUTATOR(app):
       from superset.databases.api import DatabaseRestApi
       DatabaseRestApi.page_size = 100000
   ```
   
   This causes the unpaginated init call to return all databases. 
DatabaseRestApi.max_page_size is already -1 (unlimited), so no server-side cap 
blocks this.
   
   ### Proposed fix
   
   Option A — explicitly request all databases
   Option B — defer tab rendering until SET_DATABASES is fully populated, then 
fall back to a targeted fetch for any dbId still missing from the map.
   
   ### Environment
   
   - Superset 6.1.0
   - ~885 databases in the instance
   - FAB default page_size: 20
   - DatabaseRestApi.max_page_size: -1 (unlimited)
   
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [x] I have checked Superset's logs for errors and if I found a relevant 
Python stacktrace, I included it here as text in the "additional context" 
section.


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