Copilot commented on code in PR #38716:
URL: https://github.com/apache/superset/pull/38716#discussion_r2955035617
##########
superset/models/helpers.py:
##########
@@ -2278,6 +2278,41 @@ def adhoc_column_to_sqla(
) -> ColumnElement:
raise NotImplementedError()
+ def find_adhoc_column_and_convert_to_sqla(
+ self,
+ columns: list[Column],
+ label: str,
+ template_processor: Optional[BaseTemplateProcessor] = None,
+ ) -> Optional[ColumnElement]:
+ """
+ Find an adhoc column by its label and convert it to a SQLAlchemy
column.
+
+ This helper method searches through a list of columns for an adhoc
column
+ with a matching label and converts it to a SQLAlchemy column
expression.
+
+ Args:
+ columns: List of columns to search through
+ label: The label to match against adhoc columns
+ template_processor: Optional template processor for SQL templating
+
+ Returns:
+ SQLAlchemy column element if found, None otherwise
+ """
+ adhoc_col = next(
+ (
+ c
+ for c in columns
+ if utils.is_adhoc_column(c) and c.get("label") == label
+ ),
+ None,
+ )
Review Comment:
`find_adhoc_column_and_convert_to_sqla()` relies on
`utils.is_adhoc_column()` as a type guard, but `c.get(...)` is used in the same
boolean expression. This pattern is easy to trip mypy with (attribute access on
the non-dict branch). Consider splitting the comprehension into two `if`
clauses (first `if utils.is_adhoc_column(c)` then `if c["label"] == label`) or
explicitly casting to `AdhocColumn` after the type guard.
--
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]