You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org> on 2026/04/16 15:25:40 UTC
Re: [PR] feat(semantic layers): models and DAOs [superset]
codeant-ai-for-open-source[bot] commented on code in PR #37816:
URL: https://github.com/apache/superset/pull/37816#discussion_r3094347481
##########
superset/migrations/versions/2025-11-04_11-26_33d7e0e21daa_add_semantic_layers_and_views.py:
##########
@@ -0,0 +1,166 @@
+# 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_semantic_layers_and_views
+
+Revision ID: 33d7e0e21daa
+Revises: a1b2c3d4e5f6
+Create Date: 2025-11-04 11:26:00.000000
+
+"""
+
+import uuid
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy_utils import UUIDType
+from sqlalchemy_utils.types.json import JSONType
+
+from superset.extensions import encrypted_field_factory
+from superset.migrations.shared.utils import (
+ create_fks_for_table,
+ create_table,
+ drop_table,
+)
+
+# revision identifiers, used by Alembic.
+revision = "33d7e0e21daa"
+down_revision = "a1b2c3d4e5f6"
+
+
+def upgrade():
+ # Create semantic_layers table
+ create_table(
+ "semantic_layers",
+ sa.Column("uuid", UUIDType(binary=True), default=uuid.uuid4, nullable=False),
+ # created_on and changed_on are nullable=True to match AuditMixinNullable
+ sa.Column("created_on", sa.DateTime(), nullable=True),
+ sa.Column("changed_on", sa.DateTime(), nullable=True),
+ sa.Column("name", sa.String(length=250), nullable=False),
+ sa.Column("description", sa.Text(), nullable=True),
+ sa.Column("type", sa.String(length=250), nullable=False),
+ sa.Column(
+ "configuration",
+ encrypted_field_factory.create(JSONType),
+ nullable=True,
+ ),
+ # configuration_version tracks the schema version of the configuration
+ # JSON field to aid with migrations as the schema evolves over time.
+ sa.Column(
+ "configuration_version",
+ sa.Integer(),
+ nullable=False,
+ server_default="1",
+ ),
+ sa.Column("cache_timeout", sa.Integer(), nullable=True),
+ sa.Column("created_by_fk", sa.Integer(), nullable=True),
+ sa.Column("changed_by_fk", sa.Integer(), nullable=True),
+ sa.PrimaryKeyConstraint("uuid"),
+ )
+
+ # Create foreign key constraints for semantic_layers
+ create_fks_for_table(
+ "fk_semantic_layers_created_by_fk_ab_user",
+ "semantic_layers",
+ "ab_user",
+ ["created_by_fk"],
+ ["id"],
+ )
+
+ create_fks_for_table(
+ "fk_semantic_layers_changed_by_fk_ab_user",
+ "semantic_layers",
+ "ab_user",
+ ["changed_by_fk"],
+ ["id"],
+ )
+
+ # Create semantic_views table.
+ # The integer `id` is the primary key (auto-increment across all supported
+ # databases) and `uuid` is a secondary unique identifier. This follows the
+ # standard Superset model pattern and avoids using sa.Identity(), which is
+ # not supported in MySQL or SQLite.
+ create_table(
+ "semantic_views",
+ sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
+ sa.Column("uuid", UUIDType(binary=True), default=uuid.uuid4, nullable=False),
+ # created_on and changed_on are nullable=True to match AuditMixinNullable
+ sa.Column("created_on", sa.DateTime(), nullable=True),
+ sa.Column("changed_on", sa.DateTime(), nullable=True),
+ sa.Column("name", sa.String(length=250), nullable=False),
+ sa.Column("description", sa.Text(), nullable=True),
+ sa.Column(
+ "configuration",
+ encrypted_field_factory.create(JSONType),
+ nullable=True,
+ ),
+ # configuration_version tracks the schema version of the configuration
+ # JSON field to aid with migrations as the schema evolves over time.
+ sa.Column(
+ "configuration_version",
+ sa.Integer(),
+ nullable=False,
+ server_default="1",
+ ),
+ sa.Column("cache_timeout", sa.Integer(), nullable=True),
+ sa.Column(
+ "semantic_layer_uuid",
+ UUIDType(binary=True),
+ sa.ForeignKey("semantic_layers.uuid", ondelete="CASCADE"),
+ nullable=False,
+ ),
+ sa.Column("created_by_fk", sa.Integer(), nullable=True),
+ sa.Column("changed_by_fk", sa.Integer(), nullable=True),
+ sa.PrimaryKeyConstraint("id"),
+ sa.UniqueConstraint("uuid"),
+ )
+
+ # Create foreign key constraints for semantic_views
+ create_fks_for_table(
+ "fk_semantic_views_created_by_fk_ab_user",
+ "semantic_views",
+ "ab_user",
+ ["created_by_fk"],
+ ["id"],
+ )
+
+ create_fks_for_table(
+ "fk_semantic_views_changed_by_fk_ab_user",
+ "semantic_views",
+ "ab_user",
+ ["changed_by_fk"],
+ ["id"],
+ )
+
+ # Update chart datasource constraint to allow semantic_view
+ with op.batch_alter_table("slices") as batch_op:
+ batch_op.drop_constraint("ck_chart_datasource", type_="check")
+ batch_op.create_check_constraint(
+ "ck_chart_datasource",
+ "datasource_type in ('table', 'semantic_view')",
+ )
+
+
+def downgrade():
Review Comment:
**Suggestion:** Add an explicit return type annotation to the new rollback function so the function signature is fully typed. [custom_rule]
**Severity Level:** Minor ⚠️
```suggestion
def downgrade() -> None:
```
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The rollback function also lacks a return annotation. Adding `-> None`
is valid Python and correctly documents that the function returns nothing.
</details>
[Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fmigrations%2Fversions%2F2025-11-04_11-26_33d7e0e21daa_add_semantic_layers_and_views.py%0A%2A%2ALine%3A%2A%2A%20157%3A157%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20an%20explicit%20return%20type%20annotation%20to%20the%20new%20rollback%20function%20so%20the%20function%20signature%20is%20fully%20typed.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fmigrations%2Fversions%2F2025-11-04_11-26_33d7e0e21daa_add_semantic_layers_and_views.py%0A%2A%2ALine%3A%2A%2A%20157%
3A157%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20an%20explicit%20return%20type%20annotation%20to%20the%20new%20rollback%20function%20so%20the%20function%20signature%20is%20fully%20typed.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0A)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/migrations/versions/2025-11-04_11-26_33d7e0e21daa_add_semantic_layers_and_views.py
**Line:** 157:157
**Comment:**
*Custom Rule: Add an explicit return type annotation to the new rollback function so the function signature is fully typed.
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%2F37816&comment_hash=aa4d2f11b470d183b1ce7c47bfc47dc1e18eda4ed350c27cad9f5c7766fea849&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37816&comment_hash=aa4d2f11b470d183b1ce7c47bfc47dc1e18eda4ed350c27cad9f5c7766fea849&reaction=dislike'>👎</a>
##########
superset/migrations/versions/2025-11-04_11-26_33d7e0e21daa_add_semantic_layers_and_views.py:
##########
@@ -0,0 +1,166 @@
+# 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_semantic_layers_and_views
+
+Revision ID: 33d7e0e21daa
+Revises: a1b2c3d4e5f6
+Create Date: 2025-11-04 11:26:00.000000
+
+"""
+
+import uuid
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy_utils import UUIDType
+from sqlalchemy_utils.types.json import JSONType
+
+from superset.extensions import encrypted_field_factory
+from superset.migrations.shared.utils import (
+ create_fks_for_table,
+ create_table,
+ drop_table,
+)
+
+# revision identifiers, used by Alembic.
+revision = "33d7e0e21daa"
+down_revision = "a1b2c3d4e5f6"
+
+
+def upgrade():
Review Comment:
**Suggestion:** Add an explicit return type annotation to the new migration function so the function signature is fully typed. [custom_rule]
**Severity Level:** Minor ⚠️
```suggestion
def upgrade() -> None:
```
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The migration function currently has no return annotation. Adding `-> None`
is syntactically correct and accurately reflects that the function does not
return a value.
</details>
[Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fmigrations%2Fversions%2F2025-11-04_11-26_33d7e0e21daa_add_semantic_layers_and_views.py%0A%2A%2ALine%3A%2A%2A%2044%3A44%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20an%20explicit%20return%20type%20annotation%20to%20the%20new%20migration%20function%20so%20the%20function%20signature%20is%20fully%20typed.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fmigrations%2Fversions%2F2025-11-04_11-26_33d7e0e21daa_add_semantic_layers_and_views.py%0A%2A%2ALine%3A%2A%2A%2044%3A
44%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20an%20explicit%20return%20type%20annotation%20to%20the%20new%20migration%20function%20so%20the%20function%20signature%20is%20fully%20typed.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0A)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/migrations/versions/2025-11-04_11-26_33d7e0e21daa_add_semantic_layers_and_views.py
**Line:** 44:44
**Comment:**
*Custom Rule: Add an explicit return type annotation to the new migration function so the function signature is fully typed.
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%2F37816&comment_hash=eb3f4550e7919bd3235cbf0c3d49e17ad3d70acee3b972d58f1a06cf5db80839&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37816&comment_hash=eb3f4550e7919bd3235cbf0c3d49e17ad3d70acee3b972d58f1a06cf5db80839&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: 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