codeant-ai-for-open-source[bot] commented on code in PR #41961:
URL: https://github.com/apache/superset/pull/41961#discussion_r3564772304
##########
tests/unit_tests/models/helpers_test.py:
##########
@@ -3410,3 +3410,52 @@ def fake_engine(*args, **kwargs):
# ```forecasts.original`.`total_cost``` (the regression), so this negative
# assertion catches the actual failure mode, not just an exact-string
match.
assert "`forecasts.original`" not in sql
+
+
+def test_simple_metric_quotes_column_requiring_quoting(database: Database) ->
None:
+ """
+ Regression for #30637: a SIMPLE adhoc metric that aggregates a column whose
+ name requires identifier quoting (e.g. it contains a space) must render the
+ column with the dialect's quote characters, otherwise the emitted SQL is
+ invalid for dialects that need quoting.
+
+ This exercises the metric compilation path named in the issue
+ (``adhoc_metric_to_sqla`` -> ``TableColumn.get_sqla_col`` -> ``column()``),
+ asserting the identifier is quoted rather than emitted bare.
+ """
+ from superset.connectors.sqla.models import SqlaTable, TableColumn
+ from superset.utils.core import AdhocMetricExpressionType
+
+ column_name = "Amount HT"
+ table = SqlaTable(
+ database=database,
+ schema=None,
+ table_name="test_table",
+ columns=[TableColumn(column_name=column_name, type="INTEGER")],
+ )
+ columns_by_name = {col.column_name: col for col in table.columns}
+
+ metric: AdhocMetric = {
+ "expressionType": AdhocMetricExpressionType.SIMPLE,
+ "aggregate": "SUM",
+ "column": {"column_name": column_name},
+ "label": "total",
+ }
+
+ sqla_metric = table.adhoc_metric_to_sqla(metric, columns_by_name)
Review Comment:
**Suggestion:** Add an explicit type annotation to this SQLAlchemy metric
expression variable so the new code fully complies with required type hints on
relevant variables. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This intermediate variable is introduced in modified Python code and can be
annotated with its SQLAlchemy expression type. Since the rule flags omitted
type hints on relevant variables, the missing annotation is a real violation.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 28)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=aaaf9e28193b4ce6bb1fe2f9d6455d2b&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=aaaf9e28193b4ce6bb1fe2f9d6455d2b&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:** 3445:3445
**Comment:**
*Custom Rule: Add an explicit type annotation to this SQLAlchemy metric
expression variable so the new code fully complies with required type hints on
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%2F41961&comment_hash=ff4c7ddcb3d5208e50d3a27005338cf0ea8fedb25b5e2d8c7997b77f5a58f785&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41961&comment_hash=ff4c7ddcb3d5208e50d3a27005338cf0ea8fedb25b5e2d8c7997b77f5a58f785&reaction=dislike'>๐</a>
##########
tests/unit_tests/models/helpers_test.py:
##########
@@ -3410,3 +3410,52 @@ def fake_engine(*args, **kwargs):
# ```forecasts.original`.`total_cost``` (the regression), so this negative
# assertion catches the actual failure mode, not just an exact-string
match.
assert "`forecasts.original`" not in sql
+
+
+def test_simple_metric_quotes_column_requiring_quoting(database: Database) ->
None:
+ """
+ Regression for #30637: a SIMPLE adhoc metric that aggregates a column whose
+ name requires identifier quoting (e.g. it contains a space) must render the
+ column with the dialect's quote characters, otherwise the emitted SQL is
+ invalid for dialects that need quoting.
+
+ This exercises the metric compilation path named in the issue
+ (``adhoc_metric_to_sqla`` -> ``TableColumn.get_sqla_col`` -> ``column()``),
+ asserting the identifier is quoted rather than emitted bare.
+ """
+ from superset.connectors.sqla.models import SqlaTable, TableColumn
+ from superset.utils.core import AdhocMetricExpressionType
+
+ column_name = "Amount HT"
+ table = SqlaTable(
+ database=database,
+ schema=None,
+ table_name="test_table",
+ columns=[TableColumn(column_name=column_name, type="INTEGER")],
+ )
+ columns_by_name = {col.column_name: col for col in table.columns}
Review Comment:
**Suggestion:** Add an explicit type annotation for this derived mapping to
satisfy the rule requiring type hints for relevant variables. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This new local mapping is a concrete variable that can be annotated, and the
rule requires type hints for relevant variables in modified Python code. The
code currently omits an explicit type annotation, so the suggestion matches a
real rule violation.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 28)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=8633b9b7b96044d0a5cc2155519892fc&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=8633b9b7b96044d0a5cc2155519892fc&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:** 3436:3436
**Comment:**
*Custom Rule: Add an explicit type annotation for this derived mapping
to satisfy the rule requiring type hints for 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%2F41961&comment_hash=a88d048bf531e1a2706d406ae24a3b74455ad13fd608088d3cda64c71ef159c0&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41961&comment_hash=a88d048bf531e1a2706d406ae24a3b74455ad13fd608088d3cda64c71ef159c0&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]