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>
[](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)
[](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>
[](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)
[](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: [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]