You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "sadpandajoe (via GitHub)" <gi...@apache.org> on 2026/03/25 04:58:09 UTC

[PR] fix(models): correct TabState.latest_query_id column type to match FK target [superset]

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

   ### SUMMARY
   
   `TabState.latest_query_id` is defined as `Integer` in the ORM model, but it references `Query.client_id` which is `String(11)`. The original migration from 2019 correctly created the column as `VARCHAR(11)`, so existing databases work fine — but the ORM definition has been wrong since the model was first added.
   
   This mismatch is harmless when tables are created via Alembic migrations (which use the correct type). However, any code path that calls `Model.metadata.create_all()` — such as FAB's `SecurityManager.create_db()` — will attempt to create the table using the ORM definition and fail with:
   
   ```
   psycopg2.errors.DatatypeMismatch: foreign key constraint "tab_state_latest_query_id_fkey" cannot be implemented
   DETAIL: Key columns "latest_query_id" and "client_id" are of incompatible types: integer and character varying.
   ```
   
   This was exposed by the FAB 5.1.0 → 5.2.0 upgrade in #37973. FAB 5.2.0 added the new `ab_api_key` table to the existence check in `_create_db()`, which means `create_all()` now runs on fresh databases where it previously didn't — hitting the type mismatch.
   
   The fix aligns the ORM model with the actual database schema. No migration is needed since every existing database already has the correct `VARCHAR(11)` type from the original migration.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A — backend model fix only.
   
   ### TESTING INSTRUCTIONS
   1. Verify `String` is already imported in `superset/models/sql_lab.py` (line 43)
   2. Confirm the original migration uses `sa.String(11)` for this column: `superset/migrations/versions/2019-11-13_11-05_db4b49eb0782_add_tables_for_sql_lab_state.py` line 50
   3. Confirm `Query.client_id` is `String(11)` at line 116 of `superset/models/sql_lab.py`
   4. Any test that creates tables via `Model.metadata.create_all()` on a fresh PostgreSQL database will now succeed
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
   - [ ] 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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(models): correct TabState.latest_query_id column type to match FK target [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #38837:
URL: https://github.com/apache/superset/pull/38837#issuecomment-4124140863

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **Commands**
         
   Type the following command in the pull request comment and save the comment.
         
   - `/review` - Manually triggers a full AI review.
   
   - `/pause` - Pauses automatic reviews on this pull request.
   - `/resume` - Resumes automatic reviews.
   - `/resolve` - Marks all Bito-posted review comments as resolved.
   - `/abort` - Cancels all in-progress reviews.
   
         
   Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </details>
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(models): correct TabState.latest_query_id column type to match FK target [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi merged PR #38837:
URL: https://github.com/apache/superset/pull/38837


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(models): correct TabState.latest_query_id column type to match FK target [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #38837:
URL: https://github.com/apache/superset/pull/38837#issuecomment-4123538259

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(models): correct TabState.latest_query_id column type to match FK target [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #38837:
URL: https://github.com/apache/superset/pull/38837#issuecomment-4123552241

   ## **Sequence Diagram**
   
   This PR fixes the ORM definition of TabState latest_query_id to use String11 so it matches Query client_id. With matching types, metadata create all can create the foreign key on fresh databases without datatype mismatch failures.
   
   ```mermaid
   sequenceDiagram
       participant Setup as SecurityManager
       participant ORM as SQLAlchemy Models
       participant DB as PostgreSQL
   
       Setup->>ORM: Run metadata create all
       ORM->>ORM: Define TabState latest_query_id as String11
       ORM->>DB: Create query and tab_state tables
       DB->>DB: Validate FK type compatibility
       DB-->>ORM: Create FK latest_query_id to query client_id
       ORM-->>Setup: Database setup succeeds
   ```
   
   ---
   *Generated by [CodeAnt AI](https://codeant.ai)*
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org