codeant-ai-for-open-source[bot] commented on code in PR #45795:
URL: https://github.com/apache/superset/pull/45795#discussion_r4418551560
##########
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:
✅ **Customized review instruction saved!**
**Instruction:**
> Treat the saved-query label existence check as a best-effort guard; do not
flag the lack of concurrency-safe uniqueness enforcement here without
accounting for the required migration and duplicate-row cleanup.
**Applied to:**
- `superset/daos/query.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
##########
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:
✅ **Customized review instruction saved!**
**Instruction:**
> For saved-query label uniqueness, preserve database-collation equality;
treating labels that differ only by case as duplicates is intentional because
they are ambiguous in the list.
**Applied to:**
- `superset/daos/query.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
##########
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:
✅ **Customized review instruction saved!**
**Instruction:**
> Keep saved-query uniqueness validation scoped to the REST API and SQL Lab
modal; do not require MCP coverage by moving the check into the DAO, since that
would interfere with bundle imports. Handle MCP duplicate reporting separately.
**Applied to:**
- `superset/queries/saved_queries/api.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
--
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]