codeant-ai-for-open-source[bot] commented on code in PR #35662:
URL: https://github.com/apache/superset/pull/35662#discussion_r3591689184
##########
superset/jinja_context.py:
##########
@@ -1101,28 +1104,91 @@ def get_template_processor(
def dataset_macro(
- dataset_id: int,
+ dataset_id: Union[int, str],
include_metrics: bool = False,
columns: list[str] | None = None,
from_dttm: datetime | None = None,
to_dttm: datetime | None = None,
+ schema: str | None = None,
+ catalog: str | None = None,
+ database_id: Union[int, str] | None = None,
+ alias: str | None = None,
) -> str:
"""
- Given a dataset ID, return the SQL that represents it.
+ Given a dataset ID or name, return the SQL that represents it.
+
+ If ``dataset_id`` is an integer, it is treated as the unique dataset ID and
+ the optional ``schema``, ``catalog`` and ``database_id`` parameters are
+ ignored.
+
+ If ``dataset_id`` is a string, it is treated as a dataset name. The
optional
+ ``schema``, ``catalog`` and ``database_id`` parameters are used to narrow
+ down the search when provided. If multiple datasets match the provided
+ criteria, an error is raised because the dataset name is ambiguous.
The generated SQL includes all columns (including computed) by default.
Optionally
the user can also request metrics to be included, and columns to group by.
- The from_dttm and to_dttm parameters are filled in from filter values in
explore
- views, and we take them to make those properties available to jinja
templates in
- the underlying dataset.
+ The ``from_dttm`` and ``to_dttm`` parameters are filled in from filter
values in
+ explore views, and we take them to make those properties available to jinja
+ templates in the underlying dataset.
+
+ The ``alias`` parameter allows the user to specify an explicit alias for
the
+ returned subquery.
"""
# pylint: disable=import-outside-toplevel
+ from sqlalchemy.orm.exc import MultipleResultsFound
+
from superset.daos.dataset import DatasetDAO
- dataset = DatasetDAO.find_by_id(dataset_id)
+ filters = {
+ key: value
+ for key, value in {
+ "database_id": database_id,
+ "catalog": catalog,
+ "schema": schema,
+ }.items()
+ if value is not None
+ }
Review Comment:
**Suggestion:** Add an explicit type annotation for this newly introduced
mapping so static type checking can validate expected key and value types.
[custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This is newly added Python code in the PR, and `filters` is a local variable
that can be explicitly annotated (for example, as `dict[str, Any]`). The rule
requires type hints on relevant variables that can be annotated, so the
omission 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=ac3f0bb45e574cd49689d3aef8f9dea3&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=ac3f0bb45e574cd49689d3aef8f9dea3&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/jinja_context.py
**Line:** 1144:1152
**Comment:**
*Custom Rule: Add an explicit type annotation for this newly introduced
mapping so static type checking can validate expected key and value types.
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%2F35662&comment_hash=8f33e17d2de52144772781673b4db69db0d8429d097df447ec3abd2b69e9364b&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35662&comment_hash=8f33e17d2de52144772781673b4db69db0d8429d097df447ec3abd2b69e9364b&reaction=dislike'>๐</a>
##########
superset/jinja_context.py:
##########
@@ -1101,28 +1104,91 @@ def get_template_processor(
def dataset_macro(
- dataset_id: int,
+ dataset_id: Union[int, str],
include_metrics: bool = False,
columns: list[str] | None = None,
from_dttm: datetime | None = None,
to_dttm: datetime | None = None,
+ schema: str | None = None,
+ catalog: str | None = None,
+ database_id: Union[int, str] | None = None,
+ alias: str | None = None,
) -> str:
"""
- Given a dataset ID, return the SQL that represents it.
+ Given a dataset ID or name, return the SQL that represents it.
+
+ If ``dataset_id`` is an integer, it is treated as the unique dataset ID and
+ the optional ``schema``, ``catalog`` and ``database_id`` parameters are
+ ignored.
+
+ If ``dataset_id`` is a string, it is treated as a dataset name. The
optional
+ ``schema``, ``catalog`` and ``database_id`` parameters are used to narrow
+ down the search when provided. If multiple datasets match the provided
+ criteria, an error is raised because the dataset name is ambiguous.
The generated SQL includes all columns (including computed) by default.
Optionally
the user can also request metrics to be included, and columns to group by.
- The from_dttm and to_dttm parameters are filled in from filter values in
explore
- views, and we take them to make those properties available to jinja
templates in
- the underlying dataset.
+ The ``from_dttm`` and ``to_dttm`` parameters are filled in from filter
values in
+ explore views, and we take them to make those properties available to jinja
+ templates in the underlying dataset.
+
+ The ``alias`` parameter allows the user to specify an explicit alias for
the
+ returned subquery.
"""
# pylint: disable=import-outside-toplevel
+ from sqlalchemy.orm.exc import MultipleResultsFound
+
from superset.daos.dataset import DatasetDAO
- dataset = DatasetDAO.find_by_id(dataset_id)
+ filters = {
+ key: value
+ for key, value in {
+ "database_id": database_id,
+ "catalog": catalog,
+ "schema": schema,
+ }.items()
+ if value is not None
+ }
+
+ if isinstance(dataset_id, str):
+ try:
+ dataset = DatasetDAO.get_table_by_catalog_schema_and_name(
+ table_name=dataset_id,
+ **cast(
+ dict[str, Any],
+ filters,
+ ),
+ )
+ except MultipleResultsFound as ex:
+ raise DatasetInvalidError(
+ f"Multiple datasets named '{dataset_id}' match the provided
criteria. "
+ "Please specify additional qualifiers such as schema, catalog,
"
+ "or database_id to identify a unique dataset."
+ ) from ex
+ else:
+ if filters:
+ logger.warning(
+ "Ignoring parameters %s when resolving dataset_id=%r by ID.",
+ ", ".join(filters.keys()),
+ dataset_id,
+ extra={
+ "macro": "dataset",
+ "dataset_id": dataset_id,
+ "ignored_parameters": list(filters.keys()),
+ "warning_type": "JINJA_MACRO_IGNORED_PARAMETERS",
+ },
+ )
+
+ dataset = DatasetDAO.find_by_id(dataset_id)
+
if not dataset:
- raise DatasetNotFoundError(f"Dataset {dataset_id} not found!")
+ criteria = [
+ f"{dataset_id!r}",
+ *[f"{key}={value!r}" for key, value in filters.items()],
+ ]
Review Comment:
**Suggestion:** Add a concrete type annotation for this new list variable to
make the constructed error criteria shape explicit. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This is also newly introduced Python code, and `criteria` is a local list
variable that can be annotated (for example, as `list[str]`). Since the custom
rule flags modified code that omits type hints on annotatable variables, this
is a verified 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=ffb7636ec9684a539c7e9d6f6091e156&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=ffb7636ec9684a539c7e9d6f6091e156&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/jinja_context.py
**Line:** 1186:1189
**Comment:**
*Custom Rule: Add a concrete type annotation for this new list variable
to make the constructed error criteria shape explicit.
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%2F35662&comment_hash=c3f8529dcb9504f4180733383416f3c805ca6699bbaac4ab9acbf6b0b73a0bf7&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35662&comment_hash=c3f8529dcb9504f4180733383416f3c805ca6699bbaac4ab9acbf6b0b73a0bf7&reaction=dislike'>๐</a>
##########
superset/daos/dataset.py:
##########
@@ -48,6 +48,13 @@
}
+class _Unset:
+ """Sentinel indicating that no filter should be applied."""
+
+
+_UNSET = _Unset()
Review Comment:
**Suggestion:** Add an explicit type annotation to this module-level
sentinel 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 module-level sentinel `_UNSET` is a relevant variable introduced in
the PR and can be explicitly annotated (for example, as `_Unset`). It currently
has no type hint, so this is a real violation of the Python type-hint rule.
</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=49753e4e123c4cd5885821db0a569b90&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=49753e4e123c4cd5885821db0a569b90&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/daos/dataset.py
**Line:** 55:55
**Comment:**
*Custom Rule: Add an explicit type annotation to this module-level
sentinel 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%2F35662&comment_hash=5990f788725cc516e47906de0690002437902bdd3725fb687bb3b671ac2abdfc&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35662&comment_hash=5990f788725cc516e47906de0690002437902bdd3725fb687bb3b671ac2abdfc&reaction=dislike'>๐</a>
##########
tests/unit_tests/jinja_context_test.py:
##########
@@ -906,8 +923,15 @@ def mutator(sql: str) -> str:
"""
return f"-- begin\n{sql}\n-- end"
+ dataset = SqlaTable(id=1)
Review Comment:
**Suggestion:** Add an explicit type annotation for this newly introduced
local variable to comply with the type-hint requirement. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This newly added local variable is clearly type-annotatable as a SqlaTable
instance, but it is introduced without an explicit type hint. That matches the
rule requiring type hints on new or modified Python code when annotation is
applicable.
</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=7e104c3360cc4ff397536a4ce5cb3486&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=7e104c3360cc4ff397536a4ce5cb3486&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/jinja_context_test.py
**Line:** 926:926
**Comment:**
*Custom Rule: Add an explicit type annotation for this newly introduced
local variable to comply with the type-hint 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%2F35662&comment_hash=6987bb114b944da4182fdeab9173245ee0b0ed68789307a5d36da53b86b1e1bc&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F35662&comment_hash=6987bb114b944da4182fdeab9173245ee0b0ed68789307a5d36da53b86b1e1bc&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]