bito-code-review[bot] commented on code in PR #37865:
URL: https://github.com/apache/superset/pull/37865#discussion_r2790704228


##########
superset/daos/dataset.py:
##########
@@ -49,6 +52,37 @@ class DatasetDAO(BaseDAO[SqlaTable]):
 
     base_filter = DatasourceFilter
 
+    @classmethod
+    def apply_column_operators(
+        cls,
+        query: Query,
+        column_operators: list[ColumnOperator] | None = None,
+    ) -> Query:
+        """Override to handle database_name filter via join to Database table.
+
+        database_name lives on Database, not SqlaTable, so we intercept it
+        here, join to the Database table, and apply the filter there.
+        """
+        if not column_operators:
+            return query
+
+        remaining_operators: list[ColumnOperator] = []
+        for c in column_operators:
+            if not isinstance(c, ColumnOperator):
+                c = ColumnOperator.model_validate(c)
+            if c.col == "database_name":
+                query = query.join(Database, SqlaTable.database_id == 
Database.id)
+                operator_enum = ColumnOperatorEnum(c.opr)
+                query = query.filter(
+                    operator_enum.apply(Database.database_name, c.value)
+                )
+            else:
+                remaining_operators.append(c)
+
+        if remaining_operators:
+            query = super().apply_column_operators(query, remaining_operators)
+        return query

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Query Logic Bug</b></div>
   <div id="fix">
   
   The apply_column_operators method joins to the Database table inside the 
loop for each database_name operator, which can cause multiple joins if 
multiple operators are applied to the same column. This may lead to SQL errors 
or incorrect results. Join once outside the loop if needed.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #ef6804</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



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

Reply via email to