codeant-ai-for-open-source[bot] commented on code in PR #41076:
URL: https://github.com/apache/superset/pull/41076#discussion_r3500128655
##########
superset/commands/dashboard/importers/v1/__init__.py:
##########
@@ -201,7 +205,31 @@ def _import(
overwrite
or (dashboard.id, chart_id) not in
existing_relationships
):
- dashboard_chart_ids.append((dashboard.id, chart_id))
+ target_chart_ids.append(chart_id)
+
+ if overwrite:
+ # Replace the dashboard's chart membership entirely.
+ dashboard.slices = (
+ db.session.query(Slice)
+ .filter(Slice.id.in_(target_chart_ids))
+ .all()
+ if target_chart_ids
+ else []
+ )
+ # Flush eagerly so the M2M rows land in
+ # ``dashboard_slices`` before any subsequent
+ # autoflush fires an inner-flush event handler
+ # that would reset the relationship change.
+ db.session.flush()
+ elif target_chart_ids:
+ # Append only the new associations to existing ones.
+ new_slices = (
+ db.session.query(Slice)
+ .filter(Slice.id.in_(target_chart_ids))
+ .all()
+ )
Review Comment:
**Suggestion:** Add a type annotation for the newly introduced local
collection so it complies with the required type-hint coverage for annotatable
variables. [custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
The new local variable `new_slices` is introduced without a type annotation
even though its type is readily inferable (`list[Slice]`). This matches the
rule requiring type hints for annotatable new or modified Python variables.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2a91d65e6300498ca9874eefc4b016c6&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=2a91d65e6300498ca9874eefc4b016c6&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:** superset/commands/dashboard/importers/v1/__init__.py
**Line:** 226:230
**Comment:**
*Custom Rule: Add a type annotation for the newly introduced local
collection so it complies with the required type-hint coverage for annotatable
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%2F41076&comment_hash=f46ef37da7497a70bace78bd83fb182e2ad4ffd60fdfd64748dbf796e82ca8b3&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41076&comment_hash=f46ef37da7497a70bace78bd83fb182e2ad4ffd60fdfd64748dbf796e82ca8b3&reaction=dislike'>👎</a>
##########
superset/commands/importers/v1/utils.py:
##########
@@ -387,6 +388,37 @@ def safe_insert_dashboard_chart_relationships(
)
+def _prime_versioning_unit_of_work() -> None:
+ """Ensure Continuum has a unit-of-work for the current connection.
+
+ ``dashboard_slices`` is a Continuum-tracked (versioned) association
+ table, so a raw Core INSERT/DELETE on it fires Continuum's engine-level
+ ``before_execute`` listener, which looks up a unit-of-work for the
+ connection and raises ``KeyError`` when none is registered (the same
+ failure class the dashboard test factory hit). The normal import flow
+ registers one via prior ORM flushes, so this is belt-and-suspenders for
+ a bulk relationship insert that might run before any flush on the
+ connection. No-op (the listener is detached) when version capture is
+ disabled, which is the shipped default; never allowed to break an import.
+ """
+ try:
+ # pylint: disable=import-outside-toplevel
+ from sqlalchemy_continuum import versioning_manager
+
+ # Mirror the exact condition Continuum's track_association_operations
+ # listener uses to decide whether it acts (versioning OR
+ # native_versioning), so the prime can't skip while the listener runs.
+ options = versioning_manager.options
Review Comment:
**Suggestion:** Add an explicit type annotation for this newly introduced
local variable to satisfy the type-hint requirement for annotatable variables.
[custom_rule]
**Severity Level:** Minor ⚠️
<details>
<summary><b>Why it matters? 🤔 </b></summary>
This is a newly added local variable in Python code, and it can be annotated
with a type hint. Since the rule requires type hints on annotatable variables,
the omission is a real violation.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d20de76a02b24619b73947504c07f268&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=d20de76a02b24619b73947504c07f268&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:** superset/commands/importers/v1/utils.py
**Line:** 411:411
**Comment:**
*Custom Rule: Add an explicit type annotation for this newly introduced
local variable to satisfy the type-hint requirement for annotatable 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%2F41076&comment_hash=7efe37ff4e64bc8dce1403903489a93fc0111df5325b783b565807f60be795e7&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41076&comment_hash=7efe37ff4e64bc8dce1403903489a93fc0111df5325b783b565807f60be795e7&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]