codeant-ai-for-open-source[bot] commented on code in PR #35542:
URL: https://github.com/apache/superset/pull/35542#discussion_r4291159173
##########
superset/tags/models.py:
##########
@@ -108,6 +108,8 @@ class Tag(CoreTag, AuditMixinNullable):
security_manager.user_model, secondary=user_favorite_tag_table
)
+ __table_args__ = (UniqueConstraint("name", "type",
name="uix_tag_name_type"),)
Review Comment:
**Suggestion:** With same-name custom and system rows, name-only validation
can pick the owned custom tag, then bulk deletion removes both, bypassing the
system-tag deletion guard.
**Assessment:** ๐ด `Critical` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Security`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=23a162cd3a7149fbb00efdab9bc4d28d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=23a162cd3a7149fbb00efdab9bc4d28d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/tags/models.py
**Line:** 111:111
**Comment:**
*Security: With same-name custom and system rows, name-only validation
can pick the owned custom tag, then bulk deletion removes both, bypassing the
system-tag deletion guard.
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.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35542&comment_hash=e64305fc283d136fe585d46d4ccca338c8c6420515ba48bb3f1bc0d86a11cdac&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35542&comment_hash=e64305fc283d136fe585d46d4ccca338c8c6420515ba48bb3f1bc0d86a11cdac&reaction=dislike'>๐</a>
##########
superset/migrations/versions/2025-10-06_16-05_b54f3bd8e69_update_tag_unique_constraint.py:
##########
@@ -0,0 +1,116 @@
+# 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.
+"""update_tag_unique_constraint
+
+Revision ID: b54f3bd8e69
+Revises: c179af013f48
+Create Date: 2025-10-06 16:05:00.000000
+
+"""
+
+import enum
+
+import migration_utils as utils
+from alembic import op
+from sqlalchemy import Column, Enum, Integer, MetaData, String, Table, Text
+from sqlalchemy.sql import func, select
+
+# revision identifiers, used by Alembic.
+revision = "b54f3bd8e69"
+down_revision = "c179af013f48"
+
+
+class TagType(enum.Enum):
+ # pylint: disable=invalid-name
+ custom = 1
+ type = 2
+ owner = 3
+ favorited_by = 4
+
+
+# Define the tag table structure for data operations
+metadata = MetaData()
+tag_table = Table(
+ "tag",
+ metadata,
+ Column("id", Integer, primary_key=True),
+ Column("name", String(250)),
+ Column("type", Enum(TagType)),
+ Column("description", Text),
+)
+
+old_constraint_name = "tag_name_key"
Review Comment:
**Suggestion:** The original constraint is unnamed, so MySQL creates its
unique index as `name`, not `tag_name_key`; dropping this hard-coded name fails
and stops the upgrade.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Api mismatch`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0d966649f50e41f09673368923d377b1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0d966649f50e41f09673368923d377b1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset/migrations/versions/2025-10-06_16-05_b54f3bd8e69_update_tag_unique_constraint.py
**Line:** 56:56
**Comment:**
*Api Mismatch: The original constraint is unnamed, so MySQL creates its
unique index as `name`, not `tag_name_key`; dropping this hard-coded name fails
and stops the upgrade.
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.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35542&comment_hash=d32c87758855e305602b3fc98bdca53996b8aa84a850b4e414f88000b0b9e869&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35542&comment_hash=d32c87758855e305602b3fc98bdca53996b8aa84a850b4e414f88000b0b9e869&reaction=dislike'>๐</a>
##########
superset/migrations/versions/2025-10-06_16-05_b54f3bd8e69_update_tag_unique_constraint.py:
##########
@@ -0,0 +1,116 @@
+# 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.
+"""update_tag_unique_constraint
+
+Revision ID: b54f3bd8e69
+Revises: c179af013f48
+Create Date: 2025-10-06 16:05:00.000000
+
+"""
+
+import enum
+
+import migration_utils as utils
+from alembic import op
+from sqlalchemy import Column, Enum, Integer, MetaData, String, Table, Text
+from sqlalchemy.sql import func, select
+
+# revision identifiers, used by Alembic.
+revision = "b54f3bd8e69"
+down_revision = "c179af013f48"
+
+
+class TagType(enum.Enum):
+ # pylint: disable=invalid-name
+ custom = 1
+ type = 2
+ owner = 3
+ favorited_by = 4
+
+
+# Define the tag table structure for data operations
+metadata = MetaData()
+tag_table = Table(
+ "tag",
+ metadata,
+ Column("id", Integer, primary_key=True),
+ Column("name", String(250)),
+ Column("type", Enum(TagType)),
+ Column("description", Text),
+)
+
+old_constraint_name = "tag_name_key"
+new_constraint_name = "uix_tag_name_type"
+table_name = "tag"
+new_constraint_columns = ["name", "type"]
+
+
+def upgrade():
+ """
+ Change tag unique constraint from name only to (name, type) composite.
+ This allows the same tag name to exist with different types (e.g.,
'type:dashboard'
+ can be both a system tag with type='type' and a custom tag with
type='custom').
+ """
+ bind = op.get_bind()
+
+ # Reflect the current database state to get existing tables
+ metadata.reflect(bind=bind)
+
+ # Delete duplicate tags if any, keeping the one with the lowest ID
+ min_id_subquery = (
+ select(
+ [
+ func.min(tag_table.c.id).label("min_id"),
+ tag_table.c.name,
+ tag_table.c.type,
+ ]
+ )
+ .group_by(
+ tag_table.c.name,
+ tag_table.c.type,
+ )
+ .alias("min_ids")
+ )
+
+ delete_query = tag_table.delete().where(
+ tag_table.c.id.notin_(select([min_id_subquery.c.min_id]))
+ )
+
+ bind.execute(delete_query)
Review Comment:
**Suggestion:** The cleanup can delete duplicate NULL-name tags that still
have `tagged_object` references; the foreign key rejects this DELETE, aborting
migration on databases enforcing it.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely` ยท ๐ท๏ธ `Incomplete
implementation`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=67b296ed7a3b4201a4fc91baf0252345&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=67b296ed7a3b4201a4fc91baf0252345&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset/migrations/versions/2025-10-06_16-05_b54f3bd8e69_update_tag_unique_constraint.py
**Line:** 89:93
**Comment:**
*Incomplete Implementation: The cleanup can delete duplicate NULL-name
tags that still have `tagged_object` references; the foreign key rejects this
DELETE, aborting migration on databases enforcing it.
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.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35542&comment_hash=7935d734b39bda049daf83c3e69002aaf221785a67d3429d0239624f522c2e94&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35542&comment_hash=7935d734b39bda049daf83c3e69002aaf221785a67d3429d0239624f522c2e94&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]