codeant-ai-for-open-source[bot] commented on code in PR #41964:
URL: https://github.com/apache/superset/pull/41964#discussion_r3565308684


##########
superset/connectors/sqla/models.py:
##########
@@ -1516,7 +1516,18 @@ def full_name(self) -> str:
     def dttm_cols(self) -> list[str]:
         l = [c.column_name for c in self.columns if c.is_dttm]  # noqa: E741
         if self.main_dttm_col and self.main_dttm_col not in l:
-            l.append(self.main_dttm_col)
+            # Only treat ``main_dttm_col`` as a datetime column when the 
column it
+            # points to is actually temporal. A column whose "Is Temporal" 
flag was
+            # removed must not keep being reported as a datetime column just 
because
+            # it is still referenced by ``main_dttm_col`` (#30510). When the 
column
+            # is not present on the dataset, fall back to the legacy behavior 
of
+            # trusting ``main_dttm_col``.
+            main_dttm_column = next(
+                (c for c in self.columns if c.column_name == 
self.main_dttm_col),
+                None,
+            )

Review Comment:
   **Suggestion:** Add an explicit type annotation for this new local variable 
so static typing can verify the optional TableColumn flow. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   The new local variable `main_dttm_column` is assigned an optional 
`TableColumn` but has no type annotation. This is a newly added Python variable 
in modified code and fits the rule requiring type hints where they can be 
annotated.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a2cec783cd8143869aae7fbe5c284894&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a2cec783cd8143869aae7fbe5c284894&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:** 1525:1528
   **Comment:**
        *Custom Rule: Add an explicit type annotation for this new local 
variable so static typing can verify the optional TableColumn flow.
   
   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%2F41964&comment_hash=9e7e95bca4a5f9375bbe7f1fb4bd4d32e0ba4ef662f50d48deb24ce076788ee4&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41964&comment_hash=9e7e95bca4a5f9375bbe7f1fb4bd4d32e0ba4ef662f50d48deb24ce076788ee4&reaction=dislike'>๐Ÿ‘Ž</a>



##########
tests/unit_tests/connectors/sqla/models_test.py:
##########
@@ -1177,3 +1177,46 @@ def 
test_validate_stored_expression_rejects_subquery_around_jinja(
             None,
             "(SELECT password FROM ab_user LIMIT 1) {# x #}",
         )
+
+
+def test_dttm_cols_excludes_column_after_temporal_flag_removed(
+    session: Session,
+) -> None:
+    """
+    Regression for #30510: when a column is mistakenly marked temporal, set as 
the
+    dataset's default datetime (``main_dttm_col``) and saved, then later has 
its
+    ``is_dttm`` flag removed, the dataset must stop treating that column as 
temporal.
+
+    Otherwise ``dttm_cols`` (which feeds time-column selection and the default 
time
+    filter for every chart built on the dataset) keeps returning a non-temporal
+    column, corrupting the dataset with a time filter that cannot be removed.
+    """
+    Database.metadata.create_all(session.bind)
+    database = Database(database_name="my_db", sqlalchemy_uri="sqlite://")
+
+    # A column the user mistakenly marks as temporal ("Is Temporal") and then 
picks
+    # as the dataset "Default Datetime" (``main_dttm_col``).
+    column = TableColumn(column_name="not_really_a_date", type="VARCHAR", 
is_dttm=True)

Review Comment:
   **Suggestion:** Add an explicit type annotation for this local variable so 
the new code fully complies with the type-hint rule. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   This is a new local variable in Python code and it lacks an explicit type 
annotation, so it violates the repository's type-hint requirement for 
annotatable variables.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=30044613af6e4a9ca1ad7bc7f5d51555&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=30044613af6e4a9ca1ad7bc7f5d51555&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/connectors/sqla/models_test.py
   **Line:** 1199:1199
   **Comment:**
        *Custom Rule: Add an explicit type annotation for this local variable 
so the new code fully complies with the 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%2F41964&comment_hash=d28462dbfdd836bf1897ab1d5100cfff64bad99a45303bc1378288515eb6c00b&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41964&comment_hash=d28462dbfdd836bf1897ab1d5100cfff64bad99a45303bc1378288515eb6c00b&reaction=dislike'>๐Ÿ‘Ž</a>



##########
tests/unit_tests/connectors/sqla/models_test.py:
##########
@@ -1177,3 +1177,46 @@ def 
test_validate_stored_expression_rejects_subquery_around_jinja(
             None,
             "(SELECT password FROM ab_user LIMIT 1) {# x #}",
         )
+
+
+def test_dttm_cols_excludes_column_after_temporal_flag_removed(
+    session: Session,
+) -> None:
+    """
+    Regression for #30510: when a column is mistakenly marked temporal, set as 
the
+    dataset's default datetime (``main_dttm_col``) and saved, then later has 
its
+    ``is_dttm`` flag removed, the dataset must stop treating that column as 
temporal.
+
+    Otherwise ``dttm_cols`` (which feeds time-column selection and the default 
time
+    filter for every chart built on the dataset) keeps returning a non-temporal
+    column, corrupting the dataset with a time filter that cannot be removed.
+    """
+    Database.metadata.create_all(session.bind)
+    database = Database(database_name="my_db", sqlalchemy_uri="sqlite://")
+
+    # A column the user mistakenly marks as temporal ("Is Temporal") and then 
picks
+    # as the dataset "Default Datetime" (``main_dttm_col``).
+    column = TableColumn(column_name="not_really_a_date", type="VARCHAR", 
is_dttm=True)
+    dataset = SqlaTable(

Review Comment:
   **Suggestion:** Add an explicit type annotation for this variable 
declaration to align with the required type-hinting policy. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   The new dataset variable is introduced without a type annotation, and it is 
a normal assignable local in Python test code, so it fits the rule's scope for 
annotatable variables.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=7d05c9f691054502b078b1aabb95690f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=7d05c9f691054502b078b1aabb95690f&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/connectors/sqla/models_test.py
   **Line:** 1200:1200
   **Comment:**
        *Custom Rule: Add an explicit type annotation for this variable 
declaration to align with the required type-hinting policy.
   
   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%2F41964&comment_hash=a2b4579f7ae414a66943777c2a6b15f2867fdbbb557fc7bb491611bb97da3127&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41964&comment_hash=a2b4579f7ae414a66943777c2a6b15f2867fdbbb557fc7bb491611bb97da3127&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]

Reply via email to