Bug description
We're encountering a repeated failure in SQL Lab when trying to save tab state. The backend logs reveal that database_id is being sent as a string ("postgresql-examples-1") instead of the expected integer ID, which results in an insert failure.
Connect to Superset using Docker (latest stable or master version).
Add a PostgreSQL database with name or UUID like postgresql-examples-1.
Go to SQL Lab → SQL Editor.
Create a new tab and attempt to write a simple query.
Observe the failure when Superset tries to persist the tab state.
ERROR: invalid input syntax for type integer: "postgresql-examples-1"
STATEMENT: INSERT INTO tab_state (...) VALUES (..., 'postgresql-examples-1', ...)
🛠️ Environment Info: Superset version: latest (or specify e.g., 3.0.1)
Deployment: Docker (docker-compose-non-dev.yml)
Database Backend: PostgreSQL 16
Browser: Chrome 137
OS: Linux (multiple OS tested)
Reproducible: Yes (across multiple machines and OS setups)
📎 Additional Context: The issue seems related to SQL Lab's tab state API (POST /tabstateview/).
Appears to break compatibility in environments with example DBs or custom database names.
🙏 Request: Please validate whether the frontend is passing the correct database_id, and consider adding input validation or type coercion on the backend to avoid this type mismatch.
Screenshots/recordings
No response
Superset version
master / latest-dev
Python version
3.9
Node version
16
Browser
Chrome
Additional context
No response
Checklist
- [ ] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [ ] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [ ] 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.
Comment From: dosubot[bot]
Hi @codewithz! I'm Dosu and I’m helping the superset team.
The frontend is designed to send database_id as an integer (dbId) when saving SQL Lab tab state, and the backend expects this as well. However, there is no type validation or coercion in the backend TabStateView—if the frontend ever sends a string (like a database name or slug), the backend tries to insert it directly, causing the error you’re seeing. This is a robustness gap: the backend should validate or coerce the type before writing to the database, and the frontend should ensure only integer IDs are ever sent.
No recent changes or existing issues directly address this bug, and the legacy tab state API does not use Marshmallow schemas for input validation, making it fragile to type mismatches. Defensive type checking should be added on both the frontend and backend to prevent this class of error. You can see where the backend currently lacks this validation in the TabStateView POST handler and the TabState model.
If you have any custom database registration flows or integrations, double-check that they never assign a string to dbId. Otherwise, enforcing type checks in both layers will prevent this from happening in the future.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
Comment From: stan-savransky
Hello everyone
i guess i have the same story, with clear installation (main branch with docker-compose) - but right after adding new database (in my case clickhouse) with name like "staging" and right after i try to go to sql lab - i see a lot of postgresql error trying to insert:
superset_db | 2025-06-26 16:53:09.059 UTC [197] ERROR: invalid input syntax for type integer: "clickhousedb-staging-2" at character 361
superset_db | 2025-06-26 16:53:09.059 UTC [197] STATEMENT: INSERT INTO tab_state (created_on, changed_on, extra_json, user_id, label, active, database_id, schema, catalog, sql, query_limit, latest_query_id, autorun, template_params, hide_left_bar, saved_query_id, created_by_fk, changed_by_fk) VALUES ('2025-06-26T16:53:09.059714'::timestamp, '2025-06-26T16:53:09.059716'::timestamp, '{}', 1, 'Untitled Query 1', true, 'clickhousedb-clickhousedb-staging-2-2', NULL, NULL, 'SELECT ...', 1000, NULL, false, NULL, false, NULL, 1, 1) RETURNING tab_state.id
while trying to figure it out - i found that insert tries to fetch id of database from dbs, but for some reason it combines database_name from like "type-name-id", right after i manually edit dbs table with this combined name: clickhousedb-staging-2 - i started to see:
ERROR: invalid input syntax for type integer: "clickhousedb-clickhousedb-staging-2-2" at character 361
STATEMENT: INSERT INTO tab_state (created_on, changed_on, extra_json, user_id, label, active, database_id, schema, catalog, sql, query_limit, latest_query_id, autorun, template_params, hide_left_bar, saved_query_id, created_by_fk, changed_by_fk) VALUES ('2025-06-26T16:53:24.141239'::timestamp, '2025-06-26T16:53:24.141241'::timestamp, '{}', 1, 'Untitled Query 1', true, 'clickhousedb-clickhousedb-staging-2-2', NULL, NULL, 'SELECT ...', 1000, NULL, false, NULL, false, NULL, 1, 1) RETURNING tab_state.id
any thoughts about this? hope it helps