codeant-ai-for-open-source[bot] commented on code in PR #42095:
URL: https://github.com/apache/superset/pull/42095#discussion_r3596775983
##########
tests/unit_tests/models/helpers_test.py:
##########
@@ -2157,6 +2157,117 @@ def
test_adhoc_metric_to_sqla_invalid_sql_expression_raises_validation_error(
table.adhoc_metric_to_sqla(metric, {})
+def test_adhoc_metric_normalizes_rendered_sql_once(
+ database: Database,
+ mocker: MockerFixture,
+) -> None:
+ from superset.connectors.sqla.models import SqlaTable
+
+ table = SqlaTable(database=database, schema=None, table_name="t")
+ normalizer = mocker.patch.object(
+ table.db_engine_spec,
+ "normalize_custom_sql_metric",
+ return_value="SELECT DATE_TRUNC('quarter', a)",
+ )
+ template_processor = MagicMock()
+ template_processor.process_template.side_effect = (
+ lambda expression: expression.replace("{{ unit }}", "QUARTER")
+ )
+ metric: AdhocMetric = {
+ "expressionType": "SQL",
+ "sqlExpression": "DATE_TRUNC('{{ unit }}', a)",
+ "label": "quarter",
+ }
+
+ result = table.adhoc_metric_to_sqla(
+ metric,
+ {},
+ template_processor=template_processor,
+ )
+
+ assert "DATE_TRUNC('quarter', a)" in str(result)
+ normalizer.assert_called_once_with("SELECT DATE_TRUNC('QUARTER', a)")
+
+
+def test_processed_orderby_uses_metric_normalizer_once(
+ database: Database,
+ mocker: MockerFixture,
+) -> None:
+ from superset.connectors.sqla.models import SqlaTable
+
+ table = SqlaTable(database=database, schema=None, table_name="t")
+ normalizer = MagicMock(return_value="SELECT 1 ORDER BY
DATE_TRUNC('quarter', a)")
Review Comment:
**Suggestion:** Add an explicit type annotation for this mock normalizer
variable so the new test code remains fully type-hinted. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This is a new local Python variable introduced in the test and it is not
type-annotated. Since it can be annotated, it matches the custom 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=43e94d7f27f14dce881aaf7c939cbeaf&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=43e94d7f27f14dce881aaf7c939cbeaf&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:** 2199:2199
**Comment:**
*Custom Rule: Add an explicit type annotation for this mock normalizer
variable so the new test code remains fully type-hinted.
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%2F42095&comment_hash=2b4934cba9e0fe37c8197ae1e74f0c955d0b904d79c14a901b4a36cdd2c19458&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42095&comment_hash=2b4934cba9e0fe37c8197ae1e74f0c955d0b904d79c14a901b4a36cdd2c19458&reaction=dislike'>๐</a>
##########
tests/unit_tests/models/helpers_test.py:
##########
@@ -2157,6 +2157,117 @@ def
test_adhoc_metric_to_sqla_invalid_sql_expression_raises_validation_error(
table.adhoc_metric_to_sqla(metric, {})
+def test_adhoc_metric_normalizes_rendered_sql_once(
+ database: Database,
+ mocker: MockerFixture,
+) -> None:
+ from superset.connectors.sqla.models import SqlaTable
+
+ table = SqlaTable(database=database, schema=None, table_name="t")
+ normalizer = mocker.patch.object(
+ table.db_engine_spec,
+ "normalize_custom_sql_metric",
+ return_value="SELECT DATE_TRUNC('quarter', a)",
+ )
+ template_processor = MagicMock()
Review Comment:
**Suggestion:** Add an explicit type annotation for this mocked template
processor variable to comply with the type-hint requirement for newly
introduced relevant variables. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This is newly added Python test code, and `template_processor` is a local
variable that can be annotated. It currently has no explicit type hint, so it
violates the type-hint requirement.
</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=a0dabe7dd8fa455692eb8e474cf49b4c&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=a0dabe7dd8fa455692eb8e474cf49b4c&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:** 2172:2172
**Comment:**
*Custom Rule: Add an explicit type annotation for this mocked template
processor variable to comply with 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%2F42095&comment_hash=1c183bc6c5fef10e01e432db6a3238bcbbf10674e346152ed967ad38bb5038c6&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42095&comment_hash=1c183bc6c5fef10e01e432db6a3238bcbbf10674e346152ed967ad38bb5038c6&reaction=dislike'>๐</a>
##########
tests/unit_tests/db_engine_specs/test_base.py:
##########
@@ -85,6 +85,13 @@ def test_get_text_clause_with_colon() -> None:
assert text_clause.text == "SELECT foo FROM tbl WHERE foo = '123\\:456')"
+def test_normalize_custom_sql_metric_is_identity_by_default() -> None:
+ """Unconfigured engines preserve custom metric SQL exactly."""
+ expression = "DATE_TRUNC('QUARTER', created_at) /* keep */"
+
+ assert BaseEngineSpec.normalize_custom_sql_metric(expression) == expression
Review Comment:
**Suggestion:** Add an explicit type annotation for this newly introduced
local variable so the new Python code complies with the required type-hint
rule. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
The new local variable `expression` is assigned a string literal, so its
type is directly knowable and can be annotated as required by the Python
type-hint rule. This is a real omission in the added code.
</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=03b5ccba276e4e12b9d15f5cbfc0f6c6&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=03b5ccba276e4e12b9d15f5cbfc0f6c6&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/db_engine_specs/test_base.py
**Line:** 88:92
**Comment:**
*Custom Rule: Add an explicit type annotation for this newly introduced
local variable so the new Python code complies with the required type-hint rule.
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%2F42095&comment_hash=f6e651e0f77a54d24ec14b472d038121e8cb4bbe6ee6833536961cfb113d9e68&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42095&comment_hash=f6e651e0f77a54d24ec14b472d038121e8cb4bbe6ee6833536961cfb113d9e68&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]