codeant-ai-for-open-source[bot] commented on code in PR #37371:
URL: https://github.com/apache/superset/pull/37371#discussion_r3509764220
##########
superset/connectors/sqla/models.py:
##########
@@ -1678,6 +1678,11 @@ def adhoc_metric_to_sqla(
label = utils.get_metric_name(metric, self.verbose_map)
if expression_type == utils.AdhocMetricExpressionType.SIMPLE:
+ aggregate = metric.get("aggregate")
Review Comment:
**Suggestion:** Add an explicit type annotation for `aggregate` to satisfy
the requirement for type-hinted newly introduced variables. [custom_rule]
**Severity Level:** Minor β οΈ
<details>
<summary><b>Why it matters? π€ </b></summary>
The added local variable `aggregate` is introduced without any type
annotation, and it is used in new validation and indexing logic. This matches
the rule requiring type hints for newly added relevant variables that can be
annotated.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9cdc7e9fd1c14fd7987c133c7b35b471&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=9cdc7e9fd1c14fd7987c133c7b35b471&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent π€ </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/connectors/sqla/models.py
**Line:** 1681:1681
**Comment:**
*Custom Rule: Add an explicit type annotation for `aggregate` to
satisfy the requirement for type-hinted newly introduced variables.
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%2F37371&comment_hash=17192fe9093bb92eed890127acc674bd98ed4aa565cea1ac70dcbddc147c1697&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37371&comment_hash=17192fe9093bb92eed890127acc674bd98ed4aa565cea1ac70dcbddc147c1697&reaction=dislike'>π</a>
##########
superset/models/helpers.py:
##########
@@ -2585,16 +2585,25 @@ def adhoc_metric_to_sqla(
label = utils.get_metric_name(metric)
if expression_type == utils.AdhocMetricExpressionType.SIMPLE:
+ aggregate = metric.get("aggregate")
Review Comment:
**Suggestion:** Add an explicit type annotation for the new local variable
so the aggregate valueβs expected type is clear and statically checked.
[custom_rule]
**Severity Level:** Minor β οΈ
<details>
<summary><b>Why it matters? π€ </b></summary>
This is a new local variable in modified Python code, and its type can be
annotated (for example as an optional string). Because it is introduced without
a type hint, it matches the rule requiring type hints for relevant variables
that can be annotated.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=938fe40e390749408c1e986e90e7bbec&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=938fe40e390749408c1e986e90e7bbec&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent π€ </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/models/helpers.py
**Line:** 2588:2588
**Comment:**
*Custom Rule: Add an explicit type annotation for the new local
variable so the aggregate valueβs expected type is clear and statically checked.
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%2F37371&comment_hash=6424e42d90ae793115cfbc84c13903451b29661882210a4e8fb655e43649f9e4&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37371&comment_hash=6424e42d90ae793115cfbc84c13903451b29661882210a4e8fb655e43649f9e4&reaction=dislike'>π</a>
##########
superset/connectors/sqla/models.py:
##########
@@ -1687,9 +1692,13 @@ def adhoc_metric_to_sqla(
)
else:
sqla_column = column(column_name)
- sqla_metric =
self.sqla_aggregations[metric["aggregate"]](sqla_column)
+ sqla_metric = self.sqla_aggregations[aggregate](sqla_column)
elif expression_type == utils.AdhocMetricExpressionType.SQL:
expression = metric.get("sqlExpression")
+ if not isinstance(expression, str) or not expression:
Review Comment:
**Suggestion:** Add an explicit type annotation for `expression` so the new
variable conforms to the type-hinting requirement. [custom_rule]
**Severity Level:** Minor β οΈ
<details>
<summary><b>Why it matters? π€ </b></summary>
The added local variable `expression` is introduced without a type
annotation. Since this variable is part of new validation logic and can be
annotated, the omission aligns with the Python type-hint requirement.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=42b176cbd8b94c129f346812b084e755&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=42b176cbd8b94c129f346812b084e755&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent π€ </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/connectors/sqla/models.py
**Line:** 1698:1698
**Comment:**
*Custom Rule: Add an explicit type annotation for `expression` so the
new variable conforms to the type-hinting requirement.
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%2F37371&comment_hash=6e7460d9213c2109be70afcb381864e90c9075825549fba15e71ccf6e5d7062f&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37371&comment_hash=6e7460d9213c2109be70afcb381864e90c9075825549fba15e71ccf6e5d7062f&reaction=dislike'>π</a>
##########
tests/unit_tests/models/helpers_test.py:
##########
@@ -2057,6 +2057,63 @@ def test_orderby_adhoc_column(database: Database) ->
None:
assert "ORDER BY" in sql.upper()
[email protected]("aggregate", [None, "MEDIAN"])
+def test_adhoc_metric_to_sqla_invalid_simple_aggregate_raises_validation_error(
+ database: Database,
+ aggregate: str | None,
+) -> None:
+ """
+ Test that malformed SIMPLE adhoc metrics fail with a validation error.
+ """
+ from superset.connectors.sqla.models import SqlaTable, TableColumn
+ from superset.exceptions import QueryObjectValidationError
+
+ table = SqlaTable(
+ database=database,
+ schema=None,
+ table_name="t",
+ columns=[
+ TableColumn(column_name="a"),
+ ],
+ )
Review Comment:
**Suggestion:** Add an explicit type annotation for this local variable to
satisfy the type-hint requirement for newly introduced relevant variables.
[custom_rule]
**Severity Level:** Minor β οΈ
<details>
<summary><b>Why it matters? π€ </b></summary>
The new test code introduces a local variable `table` without an explicit
type annotation. Since this is newly added Python code and `SqlaTable` is
annotatable, it matches the rule requiring type hints on relevant variables.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b6690eeeef1a49bda9a84dfac47accca&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=b6690eeeef1a49bda9a84dfac47accca&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent π€ </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/models/helpers_test.py
**Line:** 2071:2078
**Comment:**
*Custom Rule: Add an explicit type annotation for this local variable
to satisfy the type-hint requirement for newly introduced relevant variables.
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%2F37371&comment_hash=59db7de880b33bb3f74a9d23ae9c4fff2e1e9cea54c111f66124b401f337aa0d&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37371&comment_hash=59db7de880b33bb3f74a9d23ae9c4fff2e1e9cea54c111f66124b401f337aa0d&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]