codeant-ai-for-open-source[bot] commented on code in PR #39859: URL: https://github.com/apache/superset/pull/39859#discussion_r3507921161
########## tests/unit_tests/migrations/composite_pk_association_tables_test.py: ########## @@ -0,0 +1,170 @@ +# 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. +"""Unit tests for the composite-PK association-tables migration (revision +2bee73611e32). Verifies the post-migration constraint enforcement: duplicate +``(fk1, fk2)`` insertions fail with IntegrityError, distinct pairs succeed. + +Schema is built *synthetically* from the hardcoded ``AFFECTED_TABLES`` list: +each junction table is reconstructed as a composite-PK ``sa.Table`` and created +via ``metadata.create_all(engine)`` against in-memory SQLite (see +``_build_in_memory_schema``). It does not reflect the live ORM models — the list +mirrors the post-composite-PK shape the migration targets, so keep it in sync +with the migration's table set. +""" + +from importlib import import_module + +import pytest +import sqlalchemy as sa +from sqlalchemy.exc import IntegrityError + +_migration = import_module( + "superset.migrations.versions." + "2026-05-01_23-36_2bee73611e32_composite_pk_association_tables" +) + +# (table_name, fk1_col, fk2_col, fk1_parent_table, fk2_parent_table) +# Parent-table names are needed to build the FK targets in the in-memory schema. +AFFECTED_TABLES = [ + ("dashboard_roles", "dashboard_id", "role_id", "dashboards", "ab_role"), + ("dashboard_slices", "dashboard_id", "slice_id", "dashboards", "slices"), + ("dashboard_user", "user_id", "dashboard_id", "ab_user", "dashboards"), + ( + "report_schedule_user", + "user_id", + "report_schedule_id", + "ab_user", + "report_schedule", + ), + ( + "rls_filter_roles", + "role_id", + "rls_filter_id", + "ab_role", + "row_level_security_filters", + ), + ( + "rls_filter_tables", + "table_id", + "rls_filter_id", + "tables", + "row_level_security_filters", + ), + ("slice_user", "user_id", "slice_id", "ab_user", "slices"), + ("sqlatable_user", "user_id", "table_id", "ab_user", "tables"), +] Review Comment: **Suggestion:** Add an explicit type annotation to the module-level `AFFECTED_TABLES` constant to satisfy the type-hint requirement for relevant variables. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This new module-level constant is a relevant variable that can be annotated, but it is assigned without any type hint. That matches the custom type-hint requirement for new Python code. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2588273101c24d8cbe2afc0b0257b235&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=2588273101c24d8cbe2afc0b0257b235&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(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:** tests/unit_tests/migrations/composite_pk_association_tables_test.py **Line:** 42:69 **Comment:** *Custom Rule: Add an explicit type annotation to the module-level `AFFECTED_TABLES` constant to satisfy the type-hint requirement for relevant variables. 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%2F39859&comment_hash=159335782002418c1f2b8ce7343602dcb83e842675526d99153cb3efd2fcacad&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39859&comment_hash=159335782002418c1f2b8ce7343602dcb83e842675526d99153cb3efd2fcacad&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]
