codeant-ai-for-open-source[bot] commented on code in PR #45795:
URL: https://github.com/apache/superset/pull/45795#discussion_r4405294792
##########
superset/daos/query.py:
##########
@@ -90,3 +90,33 @@ def stop_query(client_id: str) -> Query:
class SavedQueryDAO(BaseDAO[SavedQuery]):
base_filter = SavedQueryFilter
+
+ @staticmethod
+ def validate_label_uniqueness(
+ label: str,
+ owner_id: int | None,
+ db_id: int | None,
+ saved_query_id: int | None = None,
+ ) -> bool:
+ """
+ Validate that no other saved query of the same owner and database uses
+ this label. The comparison is exact on the label as stored.
+
+ The check is best-effort: there is no database constraint behind it, so
+ truly concurrent requests can still race and create a duplicate.
+
+ :param label: The (already stripped) saved query label
+ :param owner_id: The id of the user owning the saved query
+ :param db_id: The id of the database the saved query targets
+ :param saved_query_id: The saved query's own id, excluded from the
+ comparison (only for validating on updates)
+ :return: True when the label is not taken
+ """
+ query = db.session.query(SavedQuery).filter(
+ SavedQuery.label == label,
Review Comment:
**Suggestion:** With a case-insensitive metadata database collation, this
equality also matches `Report` and `report`, rejecting names despite the
documented exact, case-sensitive comparison.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely` ยท ๐ท๏ธ `Incorrect condition
logic`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=77d05952c8e444ce8043cee827823935&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=77d05952c8e444ce8043cee827823935&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/daos/query.py
**Line:** 116:116
**Comment:**
*Incorrect Condition Logic: With a case-insensitive metadata database
collation, this equality also matches `Report` and `report`, rejecting names
despite the documented exact, case-sensitive comparison.
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%2F45795&comment_hash=9a49a7cfa3f552b675a0ea04b5e310a9d050ffcebb5aca149057c1f60479b6a6&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45795&comment_hash=9a49a7cfa3f552b675a0ea04b5e310a9d050ffcebb5aca149057c1f60479b6a6&reaction=dislike'>๐</a>
##########
superset/daos/query.py:
##########
@@ -90,3 +90,33 @@ def stop_query(client_id: str) -> Query:
class SavedQueryDAO(BaseDAO[SavedQuery]):
base_filter = SavedQueryFilter
+
+ @staticmethod
+ def validate_label_uniqueness(
+ label: str,
+ owner_id: int | None,
+ db_id: int | None,
+ saved_query_id: int | None = None,
+ ) -> bool:
+ """
+ Validate that no other saved query of the same owner and database uses
+ this label. The comparison is exact on the label as stored.
+
+ The check is best-effort: there is no database constraint behind it, so
+ truly concurrent requests can still race and create a duplicate.
+
+ :param label: The (already stripped) saved query label
+ :param owner_id: The id of the user owning the saved query
+ :param db_id: The id of the database the saved query targets
+ :param saved_query_id: The saved query's own id, excluded from the
+ comparison (only for validating on updates)
+ :return: True when the label is not taken
+ """
+ query = db.session.query(SavedQuery).filter(
+ SavedQuery.label == label,
+ SavedQuery.created_by_fk == owner_id,
+ SavedQuery.db_id.is_(None) if db_id is None else SavedQuery.db_id
== db_id,
+ )
+ if saved_query_id is not None:
+ query = query.filter(SavedQuery.id != saved_query_id)
+ return not db.session.query(query.exists()).scalar()
Review Comment:
**Suggestion:** Two requests can both pass this existence check before
either inserts, then commit the same owner, database, and label; duplicate
names remain possible under concurrency.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely` ยท ๐ท๏ธ `Race condition`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=84ff1e57808d423fbea09fadcc226e7b&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=84ff1e57808d423fbea09fadcc226e7b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/daos/query.py
**Line:** 122:122
**Comment:**
*Race Condition: Two requests can both pass this existence check before
either inserts, then commit the same owner, database, and label; duplicate
names remain possible under concurrency.
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%2F45795&comment_hash=6fda5ed72f0cb1cc36b115f57f76699adeaefb070c8de0ed15ff8443b4b02f98&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45795&comment_hash=6fda5ed72f0cb1cc36b115f57f76699adeaefb070c8de0ed15ff8443b4b02f98&reaction=dislike'>๐</a>
##########
superset/queries/saved_queries/api.py:
##########
@@ -203,6 +206,31 @@ def pre_add(self, item: SavedQuery) -> None:
item.user = g.user
if item.label:
item.label = item.label.strip()
+ self._validate_label_uniqueness(item)
Review Comment:
**Suggestion:** This REST hook does not run for the MCP `save_sql_query`
path, which calls `SavedQueryDAO.create` directly, so users can still create
duplicates that appear in SQL Lab.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Incomplete
implementation`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2b033a50897c4c249b1dda193e2da2db&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=2b033a50897c4c249b1dda193e2da2db&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/queries/saved_queries/api.py
**Line:** 209:209
**Comment:**
*Incomplete Implementation: This REST hook does not run for the MCP
`save_sql_query` path, which calls `SavedQueryDAO.create` directly, so users
can still create duplicates that appear in SQL Lab.
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%2F45795&comment_hash=26da2fb85914e7e781224da7217e698b4b3a5d95f728afb25085aaf60e2f76b6&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45795&comment_hash=26da2fb85914e7e781224da7217e698b4b3a5d95f728afb25085aaf60e2f76b6&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]