aminghadersohi commented on code in PR #37865:
URL: https://github.com/apache/superset/pull/37865#discussion_r2794657822
##########
superset/daos/dataset.py:
##########
@@ -49,6 +52,42 @@ 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] = []
+ db_name_operators: list[ColumnOperator] = []
+ for c in column_operators:
+ if not isinstance(c, ColumnOperator):
+ c = ColumnOperator.model_validate(c)
+ if c.col == "database_name":
+ db_name_operators.append(c)
+ else:
+ remaining_operators.append(c)
+
+ if db_name_operators:
+ query = query.join(Database, SqlaTable.database_id == Database.id)
Review Comment:
Good catch! This is a real issue — `DatasourceFilter` (our `base_filter`)
already joins `Database` for non-admin users, so adding another `JOIN` here
would cause a duplicate.
Fixed in f74fedb — switched from a `JOIN` to a subquery:
`SqlaTable.database_id.in_(SELECT Database.id WHERE ...)`. This avoids the join
entirely, so it works regardless of whether `DatasourceFilter` has already
joined `Database`.
--
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]