You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "waterWang (via GitHub)" <gi...@apache.org> on 2026/08/08 18:42:33 UTC

[PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

waterWang opened a new pull request, #42919:
URL: https://github.com/apache/superset/pull/42919

   ## Summary
   
   Fixes #42912
   
   `import_tag` catches `SQLAlchemyError` after a query-triggered autoflush failure and continues using the same SQLAlchemy `Session` without rolling back or isolating the failed per-tag operation in a SAVEPOINT.
   
   When two concurrent tag imports race on the same `TaggedObject` association (`uix_tagged_object` unique constraint), one transaction commits first and the other receives a real `UniqueViolation`. `import_tag` catches it and `continue`s, but the `Session` remains in SQLAlchemy's pending-rollback state, so the next `Session` operation raises `PendingRollbackError`.
   
   The `@transaction()` decorator on `import_tag` is a no-op when called from `ImportAssetsCommand.run()` (which is already inside a transaction), so the poisoned session is not recovered before reuse.
   
   ## Fix
   
   Wrap each per-tag operation in a SAVEPOINT via `db_session.begin_nested()`. On failure the SAVEPOINT is rolled back, the failed tag is skipped, and the `Session` remains usable for subsequent tags — the concurrent import completes without discarding unrelated imports.
   
   ## Why this approach
   
   - `begin_nested()` rolls back only the failed per-tag operation, preserving successfully-imported tags
   - A full outer `Session.rollback()` would discard the entire import, which the issue explicitly warns against
   - Mirrors the pattern used in related Session-recovery fixes (#42675, #38934, #38859)
   
   ## Testing
   
   - [ ] Test plan to be added (pending local Superset test environment)


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42919:
URL: https://github.com/apache/superset/pull/42919#issuecomment-5244400772

   @waterWang thanks for tracking down the session poisoning bug. Couple of things to look into before this is mergeable, though: codeant's two threads on utils.py look valid to me, the existing_tags cache can end up holding a Tag that never got persisted after a concurrent rollback, and new_tag_ids gets appended before the SAVEPOINT actually clears. Plus the other stuff Joe pointed out above.


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42919:
URL: https://github.com/apache/superset/pull/42919#issuecomment-5763348144

   Pushed a ruff-format fix so pre-commit's clean now, but the stuff from my last comment's still open, and this needs a rebase on master too. 
   


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on PR #42919:
URL: https://github.com/apache/superset/pull/42919#issuecomment-5243601636

   Superset uses Git pre-commit hooks courtesy of [pre-commit](https://pre-commit.com/). To install run the following:
   
   ```
   pip3 install -r requirements/development.txt
   pre-commit install
   ```
   
   A series of checks will now run when you make a git commit.
   
   Alternatively it is possible to run pre-commit by running pre-commit manually:
   
   ```
   pre-commit run --all-files
   ```


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #42919:
URL: https://github.com/apache/superset/pull/42919#issuecomment-5227641497

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/42919?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `0%` with `13 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 57.14%. Comparing base ([`127a6f9`](https://app.codecov.io/gh/apache/superset/commit/127a6f92a6d3a9298ced63968451081ce144c706?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`59cc00f`](https://app.codecov.io/gh/apache/superset/commit/59cc00f0dce9c327f830980990df9bca05d223a0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 1 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/42919?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [superset/commands/importers/v1/utils.py](https://app.codecov.io/gh/apache/superset/pull/42919?src=pr&el=tree&filepath=superset%2Fcommands%2Fimporters%2Fv1%2Futils.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY29tbWFuZHMvaW1wb3J0ZXJzL3YxL3V0aWxzLnB5) | 0.00% | [13 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/42919?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   > :exclamation:  There is a different number of reports uploaded between BASE (127a6f9) and HEAD (59cc00f). Click for more details.
   > 
   > <details><summary>HEAD has 24 uploads less than BASE</summary>
   >
   >| Flag | BASE (127a6f9) | HEAD (59cc00f) |
   >|------|------|------|
   >|python|21|2|
   >|presto|4|1|
   >|hive|3|1|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #42919      +/-   ##
   ==========================================
   - Coverage   66.42%   57.14%   -9.28%     
   ==========================================
     Files        2857     2857              
     Lines      161293   161294       +1     
     Branches    37134    37134              
   ==========================================
   - Hits       107133    92173   -14960     
   - Misses      52135    68269   +16134     
   + Partials     2025      852    -1173     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/42919/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/42919/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `38.24% <0.00%> (-0.01%)` | :arrow_down: |
   | [mysql](https://app.codecov.io/gh/apache/superset/pull/42919/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [postgres](https://app.codecov.io/gh/apache/superset/pull/42919/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/42919/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.20% <0.00%> (-0.01%)` | :arrow_down: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/42919/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.25% <0.00%> (-18.98%)` | :arrow_down: |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/42919/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/42919/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/42919?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42919:
URL: https://github.com/apache/superset/pull/42919#issuecomment-5764161550

   Thanks for this one, @waterWang. Looking at it again after trying to rebase, every line of it is already on master through your #42920 (merged Aug 15, same SAVEPOINT wrap plus the new_tag_ids fix and tests), so a rebase here collapses to nothing. Closing this as landed via #42920. sadpandajoe's point about the dropped tag association still looks real on master, so that one deserves its own small PR if you're up for it.
   


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas closed pull request #42919: fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning
URL: https://github.com/apache/superset/pull/42919


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #42919:
URL: https://github.com/apache/superset/pull/42919#discussion_r3741352452


##########
superset/commands/importers/v1/utils.py:
##########
@@ -318,28 +318,29 @@ def import_tag(
 
     for tag_name in target_tag_names:
         try:
-            tag = existing_tags.get(tag_name)
-
-            # If tag does not exist, create it
-            if tag is None:
-                description = tag_descriptions.get(tag_name, None)
-                tag = Tag(name=tag_name, description=description, type="custom")
-                db_session.add(tag)
-                existing_tags[tag_name] = tag  # Update the existing_tags dictionary
-
-            # Ensure the association with the object
-            tagged_object = (
-                db_session.query(TaggedObject)
-                .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
-                .first()
-            )
-            if not tagged_object:
-                new_tagged_object = TaggedObject(
-                    tag_id=tag.id, object_id=object_id, object_type=object_type
+            with db_session.begin_nested():
+                tag = existing_tags.get(tag_name)
+
+                # If tag does not exist, create it
+                if tag is None:
+                    description = tag_descriptions.get(tag_name, None)
+                    tag = Tag(name=tag_name, description=description, type="custom")
+                    db_session.add(tag)
+                    existing_tags[tag_name] = tag  # Update the existing_tags dict
+
+                # Ensure the association with the object
+                tagged_object = (
+                    db_session.query(TaggedObject)
+                    .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
+                    .first()
                 )
-                db_session.add(new_tagged_object)
+                if not tagged_object:
+                    new_tagged_object = TaggedObject(
+                        tag_id=tag.id, object_id=object_id, object_type=object_type
+                    )
+                    db_session.add(new_tagged_object)
 
-            new_tag_ids.append(tag.id)
+                new_tag_ids.append(tag.id)

Review Comment:
   **Suggestion:** `new_tag_ids` is updated before the nested transaction has successfully flushed and released its SAVEPOINT. If the pending association insert fails while leaving the context manager, the exception is caught but this ID remains in `new_tag_ids`, causing cleanup and the returned result to treat the failed tag as successfully imported. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Minor 🧹</summary>
   
   ```mdx
   - ⚠️ `import_tag()` returns IDs for failed associations.
   - ⚠️ Concurrent imports produce inaccurate tag results.
   - ⚠️ Cleanup decisions use stale success state.
   ```
   </details>
   
   [![Fix in Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3f8990bd4e7e46378681cb9e568711a2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [![Fix in VSCode Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=3f8990bd4e7e46378681cb9e568711a2&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:** 343:343
   **Comment:**
   	*Logic Error: `new_tag_ids` is updated before the nested transaction has successfully flushed and released its SAVEPOINT. If the pending association insert fails while leaving the context manager, the exception is caught but this ID remains in `new_tag_ids`, causing cleanup and the returned result to treat the failed tag as successfully imported.
   
   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%2F42919&comment_hash=560402351cf088c4c69ad8d3478ad24ab3924d94fb2b0551c5fc8684db1ec65a&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42919&comment_hash=560402351cf088c4c69ad8d3478ad24ab3924d94fb2b0551c5fc8684db1ec65a&reaction=dislike'>👎</a>



##########
superset/commands/importers/v1/utils.py:
##########
@@ -318,28 +318,29 @@ def import_tag(
 
     for tag_name in target_tag_names:
         try:
-            tag = existing_tags.get(tag_name)
-
-            # If tag does not exist, create it
-            if tag is None:
-                description = tag_descriptions.get(tag_name, None)
-                tag = Tag(name=tag_name, description=description, type="custom")
-                db_session.add(tag)
-                existing_tags[tag_name] = tag  # Update the existing_tags dictionary
-
-            # Ensure the association with the object
-            tagged_object = (
-                db_session.query(TaggedObject)
-                .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
-                .first()
-            )
-            if not tagged_object:
-                new_tagged_object = TaggedObject(
-                    tag_id=tag.id, object_id=object_id, object_type=object_type
+            with db_session.begin_nested():
+                tag = existing_tags.get(tag_name)
+
+                # If tag does not exist, create it
+                if tag is None:
+                    description = tag_descriptions.get(tag_name, None)
+                    tag = Tag(name=tag_name, description=description, type="custom")
+                    db_session.add(tag)
+                    existing_tags[tag_name] = tag  # Update the existing_tags dict

Review Comment:
   **Suggestion:** When two imports concurrently create the same tag, the losing insert raises a uniqueness error and rolls back this SAVEPOINT. The newly constructed `Tag` is then no longer persistent, but `existing_tags` still points to it, so this import skips the association instead of re-querying the tag row created by the winning transaction. Re-fetch the existing tag after the uniqueness conflict before continuing the association operation. [race condition]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Concurrent imports can omit requested tag associations.
   - ⚠️ Asset imports report success with incomplete tagging.
   - ⚠️ The losing transaction does not reuse the winning tag row.
   ```
   </details>
   
   [![Fix in Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=6e69fe0c1add41d48af199c2e3967f0f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [![Fix in VSCode Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=6e69fe0c1add41d48af199c2e3967f0f&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:** 325:329
   **Comment:**
   	*Race Condition: When two imports concurrently create the same tag, the losing insert raises a uniqueness error and rolls back this SAVEPOINT. The newly constructed `Tag` is then no longer persistent, but `existing_tags` still points to it, so this import skips the association instead of re-querying the tag row created by the winning transaction. Re-fetch the existing tag after the uniqueness conflict before continuing the association operation.
   
   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%2F42919&comment_hash=fabae5d7b31dfe153aa025a929236ea827d07e8168fd6cbd9db95b06264793a0&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42919&comment_hash=fabae5d7b31dfe153aa025a929236ea827d07e8168fd6cbd9db95b06264793a0&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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42919:
URL: https://github.com/apache/superset/pull/42919#issuecomment-5611035771

   @waterWang the SAVEPOINT approach is the right call for the poisoning bug, but the two gaps I flagged in August — stale `existing_tags` entries after a rollback, and `new_tag_ids` appending before the SAVEPOINT clears — still need fixing before this can land.


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #42919:
URL: https://github.com/apache/superset/pull/42919#discussion_r3820906177


##########
superset/commands/importers/v1/utils.py:
##########
@@ -318,28 +318,29 @@ def import_tag(
 
     for tag_name in target_tag_names:
         try:
-            tag = existing_tags.get(tag_name)
-
-            # If tag does not exist, create it
-            if tag is None:
-                description = tag_descriptions.get(tag_name, None)
-                tag = Tag(name=tag_name, description=description, type="custom")
-                db_session.add(tag)
-                existing_tags[tag_name] = tag  # Update the existing_tags dictionary
-
-            # Ensure the association with the object
-            tagged_object = (
-                db_session.query(TaggedObject)
-                .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
-                .first()
-            )
-            if not tagged_object:
-                new_tagged_object = TaggedObject(
-                    tag_id=tag.id, object_id=object_id, object_type=object_type
+            with db_session.begin_nested():
+                tag = existing_tags.get(tag_name)
+
+                # If tag does not exist, create it
+                if tag is None:
+                    description = tag_descriptions.get(tag_name, None)
+                    tag = Tag(name=tag_name, description=description, type="custom")
+                    db_session.add(tag)
+                    existing_tags[tag_name] = tag  # Update the existing_tags dict

Review Comment:
   Agreed—the savepoint rolls back the newly inserted tag but leaves it cached, so a concurrent create makes this import skip the requested association. Could this re-query the tag after the uniqueness conflict before continuing?



##########
superset/commands/importers/v1/utils.py:
##########
@@ -318,28 +318,29 @@ def import_tag(
 
     for tag_name in target_tag_names:
         try:
-            tag = existing_tags.get(tag_name)
-
-            # If tag does not exist, create it
-            if tag is None:
-                description = tag_descriptions.get(tag_name, None)
-                tag = Tag(name=tag_name, description=description, type="custom")
-                db_session.add(tag)
-                existing_tags[tag_name] = tag  # Update the existing_tags dictionary
-
-            # Ensure the association with the object
-            tagged_object = (
-                db_session.query(TaggedObject)
-                .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
-                .first()
-            )
-            if not tagged_object:
-                new_tagged_object = TaggedObject(
-                    tag_id=tag.id, object_id=object_id, object_type=object_type
+            with db_session.begin_nested():
+                tag = existing_tags.get(tag_name)
+
+                # If tag does not exist, create it
+                if tag is None:
+                    description = tag_descriptions.get(tag_name, None)
+                    tag = Tag(name=tag_name, description=description, type="custom")
+                    db_session.add(tag)
+                    existing_tags[tag_name] = tag  # Update the existing_tags dict
+
+                # Ensure the association with the object
+                tagged_object = (
+                    db_session.query(TaggedObject)
+                    .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
+                    .first()
                 )
-                db_session.add(new_tagged_object)
+                if not tagged_object:
+                    new_tagged_object = TaggedObject(
+                        tag_id=tag.id, object_id=object_id, object_type=object_type
+                    )
+                    db_session.add(new_tagged_object)
 
-            new_tag_ids.append(tag.id)
+                new_tag_ids.append(tag.id)

Review Comment:
   Agreed—an error while releasing the savepoint rolls back the association, but its tag ID has already been recorded as successful. Could this append only after the nested block exits?



-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #42919:
URL: https://github.com/apache/superset/pull/42919#issuecomment-5720119320

   ### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
   
   
   |  Name | Link |
   |:-:|------------------------|
   |<span aria-hidden="true">🔨</span> Latest commit | 6d00d486cd46553830b4d40e914c23f964505f37 |
   |<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6aac3fd9d3053500071b9174 |
   |<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-42919--superset-docs-preview.netlify.app](https://deploy-preview-42919--superset-docs-preview.netlify.app) |
   |<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />![QR Code](https://app.netlify.com/qr-code/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2RlcGxveS1wcmV2aWV3LTQyOTE5LS1zdXBlcnNldC1kb2NzLXByZXZpZXcubmV0bGlmeS5hcHAifQ.fhxXPtaLti10pTPpPz6W4MZ0GBQfkO5NgtBndxiF4pE)<br /><br />_Use your smartphone camera to open QR code link._</details> |
   |<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#q1YqKMrPLShRslJS0lFKKkrMS84AstMyK_Qzcwvyi0p0SxLTdYsTy1IL8jPzSoBqUlILcvIrPVOAqswSE5ON01IsU4wNTI1NDQwMzA2TLA3NTZRqAQ) |
   ---
   <!-- [superset-docs-preview Preview](https://deploy-preview-42919--superset-docs-preview.netlify.app) -->
   _To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42919:
URL: https://github.com/apache/superset/pull/42919#issuecomment-5719769696

   @waterWang the SAVEPOINT approach is the right fix for the session poisoning, but @sadpandajoe caught some legit gaps in the recovery path that are still open, most recently the failure path dropping pre-existing tag associations. Want to see those addressed before this merges.
   
   Also needs a rebase on `master`, and pre-commit's failing (ruff-format wants a reformat).
   


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42919:
URL: https://github.com/apache/superset/pull/42919#issuecomment-5722135767

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **Commands**
         
   Type the following command in the pull request comment and save the comment.
         
   - `/review` - Manually triggers an incremental AI Review.
   - `/review full` - Manually triggers a full AI Review.
   
   - `/pause` - Pauses automatic reviews on this pull request.
   - `/resume` - Resumes automatic reviews.
   - `/resolve` - Marks all Bito-posted review comments as resolved.
   - `/abort` - Cancels all in-progress reviews.
   
         
   Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </details>
   


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #42919:
URL: https://github.com/apache/superset/pull/42919#discussion_r3870754479


##########
superset/commands/importers/v1/utils.py:
##########
@@ -318,28 +318,29 @@ def import_tag(
 
     for tag_name in target_tag_names:
         try:
-            tag = existing_tags.get(tag_name)
-
-            # If tag does not exist, create it
-            if tag is None:
-                description = tag_descriptions.get(tag_name, None)
-                tag = Tag(name=tag_name, description=description, type="custom")
-                db_session.add(tag)
-                existing_tags[tag_name] = tag  # Update the existing_tags dictionary
-
-            # Ensure the association with the object
-            tagged_object = (
-                db_session.query(TaggedObject)
-                .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
-                .first()
-            )
-            if not tagged_object:
-                new_tagged_object = TaggedObject(
-                    tag_id=tag.id, object_id=object_id, object_type=object_type
+            with db_session.begin_nested():

Review Comment:
   This changes the error-recovery boundary, but the existing tag test covers only successful creation and the disabled flag. A savepoint-release failure can still regress to a poisoned session or leave a failed association reported as imported. Could this add a two-tag regression that forces the first nested transaction to fail and asserts the second tag is processed while the failed association is absent from the returned IDs?



-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42919:
URL: https://github.com/apache/superset/pull/42919#issuecomment-5227561658

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #42919:
URL: https://github.com/apache/superset/pull/42919#discussion_r3990863082


##########
superset/commands/importers/v1/utils.py:
##########
@@ -318,28 +318,29 @@ def import_tag(
 
     for tag_name in target_tag_names:
         try:
-            tag = existing_tags.get(tag_name)
-
-            # If tag does not exist, create it
-            if tag is None:
-                description = tag_descriptions.get(tag_name, None)
-                tag = Tag(name=tag_name, description=description, type="custom")
-                db_session.add(tag)
-                existing_tags[tag_name] = tag  # Update the existing_tags dictionary
-
-            # Ensure the association with the object
-            tagged_object = (
-                db_session.query(TaggedObject)
-                .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
-                .first()
-            )
-            if not tagged_object:
-                new_tagged_object = TaggedObject(
-                    tag_id=tag.id, object_id=object_id, object_type=object_type
+            with db_session.begin_nested():

Review Comment:
   A recoverable error while processing an already attached requested tag leaves its ID out of `new_tag_ids`, so the cleanup below deletes that association even though the import still requests it. Could the failure path preserve pre-existing requested associations?



-- 
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


Re: [PR] fix(import): wrap per-tag tag operation in SAVEPOINT to prevent Session poisoning [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #42919:
URL: https://github.com/apache/superset/pull/42919#discussion_r3820909182


##########
superset/commands/importers/v1/utils.py:
##########
@@ -318,28 +318,29 @@ def import_tag(
 
     for tag_name in target_tag_names:
         try:
-            tag = existing_tags.get(tag_name)
-
-            # If tag does not exist, create it
-            if tag is None:
-                description = tag_descriptions.get(tag_name, None)
-                tag = Tag(name=tag_name, description=description, type="custom")
-                db_session.add(tag)
-                existing_tags[tag_name] = tag  # Update the existing_tags dictionary
-
-            # Ensure the association with the object
-            tagged_object = (
-                db_session.query(TaggedObject)
-                .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
-                .first()
-            )
-            if not tagged_object:
-                new_tagged_object = TaggedObject(
-                    tag_id=tag.id, object_id=object_id, object_type=object_type
+            with db_session.begin_nested():
+                tag = existing_tags.get(tag_name)
+
+                # If tag does not exist, create it
+                if tag is None:
+                    description = tag_descriptions.get(tag_name, None)
+                    tag = Tag(name=tag_name, description=description, type="custom")
+                    db_session.add(tag)
+                    existing_tags[tag_name] = tag  # Update the existing_tags dict

Review Comment:
   Yes, this is a valid race. After the savepoint rollback, `existing_tags[tag_name]` still references the rolled-back `Tag` instance, so the next iteration can skip the association.
   
   On a uniqueness error, discard the stale instance, re-query the committed `Tag`, update `existing_tags`, and retry the association in a new savepoint. This should be limited to an integrity/unique-violation error rather than every `SQLAlchemyError`.
   
   For example:
   
   ```python
           except IntegrityError as err:
               logger.error(
                   "Error processing tag '%s' for %s ID %d: %s",
                   tag_name,
                   object_type,
                   object_id,
                   err,
               )
   
               # The failed savepoint may have rolled back a concurrently-created Tag.
               existing_tags.pop(tag_name, None)
               tag = (
                   db_session.query(Tag)
                   .filter(Tag.name == tag_name)
                   .one_or_none()
               )
   
               if tag is None:
                   continue
   
               existing_tags[tag_name] = tag
   
               try:
                   with db_session.begin_nested():
                       if not (
                           db_session.query(TaggedObject)
                           .filter_by(
                               object_id=object_id,
                               object_type=object_type,
                               tag_id=tag.id,
                           )
                           .first()
                       ):
                           db_session.add(
                               TaggedObject(
                                   tag_id=tag.id,
                                   object_id=object_id,
                                   object_type=object_type,
                               )
                           )
                       new_tag_ids.append(tag.id)
               except SQLAlchemyError:
                   continue
   ```
   
   The exact exception check should match Superset’s existing database-dialect utilities for unique violations. This preserves the savepoint recovery behavior while ensuring the losing import reuses the winning transaction’s `Tag` row and creates the requested association.



##########
superset/commands/importers/v1/utils.py:
##########
@@ -318,28 +318,29 @@ def import_tag(
 
     for tag_name in target_tag_names:
         try:
-            tag = existing_tags.get(tag_name)
-
-            # If tag does not exist, create it
-            if tag is None:
-                description = tag_descriptions.get(tag_name, None)
-                tag = Tag(name=tag_name, description=description, type="custom")
-                db_session.add(tag)
-                existing_tags[tag_name] = tag  # Update the existing_tags dictionary
-
-            # Ensure the association with the object
-            tagged_object = (
-                db_session.query(TaggedObject)
-                .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
-                .first()
-            )
-            if not tagged_object:
-                new_tagged_object = TaggedObject(
-                    tag_id=tag.id, object_id=object_id, object_type=object_type
+            with db_session.begin_nested():
+                tag = existing_tags.get(tag_name)
+
+                # If tag does not exist, create it
+                if tag is None:
+                    description = tag_descriptions.get(tag_name, None)
+                    tag = Tag(name=tag_name, description=description, type="custom")
+                    db_session.add(tag)
+                    existing_tags[tag_name] = tag  # Update the existing_tags dict
+
+                # Ensure the association with the object
+                tagged_object = (
+                    db_session.query(TaggedObject)
+                    .filter_by(object_id=object_id, object_type=object_type, tag_id=tag.id)
+                    .first()
                 )
-                db_session.add(new_tagged_object)
+                if not tagged_object:
+                    new_tagged_object = TaggedObject(
+                        tag_id=tag.id, object_id=object_id, object_type=object_type
+                    )
+                    db_session.add(new_tagged_object)
 
-            new_tag_ids.append(tag.id)
+                new_tag_ids.append(tag.id)

Review Comment:
   Yes. The append should occur after the `begin_nested()` context exits successfully, so any flush or SAVEPOINT release failure is handled before recording the tag as imported:
   
   ```python
           try:
               with db_session.begin_nested():
                   tag = existing_tags.get(tag_name)
   
                   if tag is None:
                       description = tag_descriptions.get(tag_name)
                       tag = Tag(name=tag_name, description=description, type="custom")
                       db_session.add(tag)
                       existing_tags[tag_name] = tag
   
                   tagged_object = (
                       db_session.query(TaggedObject)
                       .filter_by(
                           object_id=object_id,
                           object_type=object_type,
                           tag_id=tag.id,
                       )
                       .first()
                   )
                   if not tagged_object:
                       db_session.add(
                           TaggedObject(
                               tag_id=tag.id,
                               object_id=object_id,
                               object_type=object_type,
                           )
                       )
   
               # Only record success after the SAVEPOINT was released.
               new_tag_ids.append(tag.id)
   
           except SQLAlchemyError as err:
               logger.error(...)
               continue
   ```
   
   This ensures a failed flush or SAVEPOINT release cannot leave a stale ID in `new_tag_ids`, so both the return value and subsequent cleanup reflect only successfully processed tags.



-- 
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