codeant-ai-for-open-source[bot] commented on code in PR #38469: URL: https://github.com/apache/superset/pull/38469#discussion_r3020657536
########## superset/migrations/versions/2026-03-06_12-00_c0d1e2f3a4b5_add_upstream_oauth_tokens.py: ########## @@ -0,0 +1,74 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""add_upstream_oauth_tokens + +Revision ID: c0d1e2f3a4b5 +Revises: a1b2c3d4e5f6 +Create Date: 2026-03-06 12:00:00.000000 + +""" + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "c0d1e2f3a4b5" +down_revision = "a1b2c3d4e5f6" + + +def upgrade() -> None: + op.create_table( + "upstream_oauth_tokens", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("user_id", sa.Integer(), nullable=False), + sa.Column("provider", sa.String(256), nullable=False), + sa.Column("access_token", sa.Text(), nullable=True), + sa.Column("access_token_expiration", sa.DateTime(), nullable=True), + sa.Column("refresh_token", sa.Text(), nullable=True), + sa.Column("created_on", sa.DateTime(), nullable=True), + sa.Column("changed_on", sa.DateTime(), nullable=True), + sa.Column("created_by_fk", sa.Integer(), nullable=True), + sa.Column("changed_by_fk", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["created_by_fk"], + ["ab_user.id"], + ), + sa.ForeignKeyConstraint( + ["changed_by_fk"], + ["ab_user.id"], + ), + sa.ForeignKeyConstraint( + ["user_id"], + ["ab_user.id"], + ondelete="CASCADE", + ), + sa.PrimaryKeyConstraint("id"), + ) + op.create_unique_constraint( + "uq_upstream_oauth_tokens_user_provider", + "upstream_oauth_tokens", Review Comment: **Suggestion:** Creating a unique constraint with `op.create_unique_constraint` after table creation uses an ALTER TABLE operation, which is not supported by SQLite and will make migration upgrade fail in SQLite-based environments. Use batch alter mode so the constraint creation is SQLite-safe. [possible bug] <details> <summary><b>Severity Level:</b> Critical 🚨</summary> ```mdx - ❌ SQLite deployments cannot apply migration; Superset fails to start. - ⚠️ CI/tests using SQLite metadata blocked by migration failure. ``` </details> ```suggestion with op.batch_alter_table("upstream_oauth_tokens") as batch_op: batch_op.create_unique_constraint( "uq_upstream_oauth_tokens_user_provider", ``` <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Start Superset with the default metadata DB configuration using SQLite (`SQLALCHEMY_DATABASE_URI` is set to a SQLite URI in `superset/config.py:237-239`). 2. Run `superset db upgrade`, which uses Alembic with config from `superset/migrations/env.py:10-18` and applies all migration scripts under `superset/migrations/versions/`. 3. When Alembic reaches `upgrade()` in `superset/migrations/versions/2026-03-06_12-00_c0d1e2f3a4b5_add_upstream_oauth_tokens.py:33-65`, it successfully executes `op.create_table("upstream_oauth_tokens", ...)` at lines 34-60. 4. Immediately after, Alembic executes `op.create_unique_constraint("uq_upstream_oauth_tokens_user_provider", "upstream_oauth_tokens", ["user_id", "provider"])` at lines 61-65, which issues a constraint-creation ALTER operation on the SQLite dialect; SQLite's Alembic implementation does not support direct ALTER ADD CONSTRAINT, so (as seen in earlier migrations that either use `batch_alter_table` or catch exceptions, e.g. `b4456560d4f3_change_table_unique_constraint.py:32-40` and `c878781977c6_alert_reports_shared_uniqueness.py:73-29`) this raises a `NotImplementedError` ("No support for ALTER of constraints in SQLite dialect") and causes `superset db upgrade` to fail, leaving the app reporting pending migrations at startup via `superset/app.py:16-19`. ``` </details> <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset/migrations/versions/2026-03-06_12-00_c0d1e2f3a4b5_add_upstream_oauth_tokens.py **Line:** 61:63 **Comment:** *Possible Bug: Creating a unique constraint with `op.create_unique_constraint` after table creation uses an ALTER TABLE operation, which is not supported by SQLite and will make migration upgrade fail in SQLite-based environments. Use batch alter mode so the constraint creation is SQLite-safe. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38469&comment_hash=8a476861200a11a4b0518ff15b501e5db68e6cf637585b9f5890dd54d1fae8f4&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38469&comment_hash=8a476861200a11a4b0518ff15b501e5db68e6cf637585b9f5890dd54d1fae8f4&reaction=dislike'>👎</a> -- 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]
