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


##########
superset/utils/date_parser.py:
##########
@@ -426,10 +426,27 @@ def get_since_until(  # pylint: 
disable=too-many-arguments,too-many-locals,too-m
         return None, None
 
     if time_range and time_range.startswith("Last") and separator not in 
time_range:
-        time_range = time_range + separator + _relative_end
+        # For granular time units (second/minute/hour), "today" (midnight) 
would be
+        # earlier than the computed since time (e.g. now-1h), causing a
+        # "From date cannot be larger than to date" error. Always use "now" for
+        # sub-day units so that the until bound is consistent with the since 
bound.
+        _granular_last_pattern = (
+            r"^Last\s+[0-9]+\s+(second|minute|hour)s?$"
+        )

Review Comment:
   **Suggestion:** Add an explicit type annotation for this newly introduced 
regex pattern variable. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The added variable is a regex pattern string and can be trivially annotated 
as `str`, so the lack of a type hint in newly modified Python code violates the 
type-hint rule.
   </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=d0cd753cd1164f8e8ac74f042b692e7e&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=d0cd753cd1164f8e8ac74f042b692e7e&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/utils/date_parser.py
   **Line:** 433:435
   **Comment:**
        *Custom Rule: Add an explicit type annotation for this newly introduced 
regex pattern variable.
   
   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%2F41527&comment_hash=b6010a9951b278996b46fd0b3d6a59fa104264878cb2a23aee59b77b1fb2b57e&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41527&comment_hash=b6010a9951b278996b46fd0b3d6a59fa104264878cb2a23aee59b77b1fb2b57e&reaction=dislike'>👎</a>



##########
tests/unit_tests/utils/date_parser_tests.py:
##########
@@ -760,3 +760,98 @@ def 
test_datetime_eval_does_not_emit_parsedatetime_debug_logs(
         "flood production logs. Records: "
         + repr([(r.levelname, r.getMessage()) for r in parsedatetime_records])
     )
+
+
+@patch("superset.utils.date_parser.parse_human_datetime", 
mock_parse_human_datetime)
+def test_get_since_until_sub_hour_presets() -> None:
+    """Verify that sub-hour presets ('Last 5 minutes', 'Last 15 minutes',
+    'Last 30 minutes', 'Last 1 hour') resolve to the expected datetime pairs
+    when relative_end='now'."""
+    result: tuple[Optional[datetime], Optional[datetime]]
+
+    result = get_since_until("Last 5 minutes", relative_end="now")
+    expected = datetime(2016, 11, 7, 9, 25, 10), datetime(2016, 11, 7, 9, 30, 
10)
+    assert result == expected
+
+    result = get_since_until("Last 15 minutes", relative_end="now")
+    expected = datetime(2016, 11, 7, 9, 15, 10), datetime(2016, 11, 7, 9, 30, 
10)
+    assert result == expected
+
+    result = get_since_until("Last 30 minutes", relative_end="now")
+    expected = datetime(2016, 11, 7, 9, 0, 10), datetime(2016, 11, 7, 9, 30, 
10)
+    assert result == expected
+
+    result = get_since_until("Last 1 hour", relative_end="now")
+    expected = datetime(2016, 11, 7, 8, 30, 10), datetime(2016, 11, 7, 9, 30, 
10)
+    assert result == expected
+
+
+@patch("superset.utils.date_parser.parse_human_datetime", 
mock_parse_human_datetime)
+def test_get_since_until_granular_units_use_now_by_default() -> None:
+    """Verify that 'Last/Next N <granular_unit>' uses 'now' as the end/start
+    bound when no explicit relative_end/relative_start is provided, so that
+    since is always less than until regardless of the time of day.
+
+    Regression test for the 'From date cannot be larger than to date' error
+    that occurred because the default relative_end='today' (midnight) was
+    earlier than the computed since time (e.g. now - 1 hour).
+    """
+    result: tuple[Optional[datetime], Optional[datetime]]
+
+    # --- Last N <granular_unit> without explicit relative_end ---
+    # All of these must satisfy since < until at any time of day.
+
+    result = get_since_until("Last 1 hour")
+    assert result[0] is not None
+    assert result[1] is not None
+    assert result[0] < result[1], "Last 1 hour: since must be before until"
+    # until should be 'now', not 'today' (midnight)
+    expected_until = datetime(2016, 11, 7, 9, 30, 10)  # mock 'now'
+    assert result[1] == expected_until
+    expected_since = datetime(2016, 11, 7, 8, 30, 10)  # now - 1h

Review Comment:
   **Suggestion:** Add explicit type annotations to these newly introduced 
expected datetime locals so all relevant new variables are type hinted. 
[custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The newly introduced locals `expected_until` and `expected_since` are 
unannotated despite being straightforward datetime variables, so this is a real 
omission under the type-hint rule.
   </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=f9393cae1d3349a887ca50611769e77e&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=f9393cae1d3349a887ca50611769e77e&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/utils/date_parser_tests.py
   **Line:** 809:811
   **Comment:**
        *Custom Rule: Add explicit type annotations to these newly introduced 
expected datetime locals so all relevant new variables are 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%2F41527&comment_hash=75e700cbefbce5244e6e99956bfaedd18436f9bd31ed558be22389adff654f18&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41527&comment_hash=75e700cbefbce5244e6e99956bfaedd18436f9bd31ed558be22389adff654f18&reaction=dislike'>👎</a>



##########
tests/unit_tests/utils/date_parser_tests.py:
##########
@@ -760,3 +760,98 @@ def 
test_datetime_eval_does_not_emit_parsedatetime_debug_logs(
         "flood production logs. Records: "
         + repr([(r.levelname, r.getMessage()) for r in parsedatetime_records])
     )
+
+
+@patch("superset.utils.date_parser.parse_human_datetime", 
mock_parse_human_datetime)
+def test_get_since_until_sub_hour_presets() -> None:
+    """Verify that sub-hour presets ('Last 5 minutes', 'Last 15 minutes',
+    'Last 30 minutes', 'Last 1 hour') resolve to the expected datetime pairs
+    when relative_end='now'."""
+    result: tuple[Optional[datetime], Optional[datetime]]
+
+    result = get_since_until("Last 5 minutes", relative_end="now")
+    expected = datetime(2016, 11, 7, 9, 25, 10), datetime(2016, 11, 7, 9, 30, 
10)
+    assert result == expected
+
+    result = get_since_until("Last 15 minutes", relative_end="now")
+    expected = datetime(2016, 11, 7, 9, 15, 10), datetime(2016, 11, 7, 9, 30, 
10)
+    assert result == expected
+
+    result = get_since_until("Last 30 minutes", relative_end="now")
+    expected = datetime(2016, 11, 7, 9, 0, 10), datetime(2016, 11, 7, 9, 30, 
10)
+    assert result == expected
+
+    result = get_since_until("Last 1 hour", relative_end="now")
+    expected = datetime(2016, 11, 7, 8, 30, 10), datetime(2016, 11, 7, 9, 30, 
10)

Review Comment:
   **Suggestion:** Add an explicit type annotation for the repeatedly 
reassigned `expected` tuple in this new test to satisfy the type-hint 
requirement for relevant local variables. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The new test introduces repeatedly reassigned local variables like 
`expected` without any type annotation, which matches the custom rule requiring 
type hints for relevant variables that can be annotated.
   </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=c0476998b3d04c2c995da12a33c2306a&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=c0476998b3d04c2c995da12a33c2306a&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/utils/date_parser_tests.py
   **Line:** 772:785
   **Comment:**
        *Custom Rule: Add an explicit type annotation for the repeatedly 
reassigned `expected` tuple in this new test to satisfy the type-hint 
requirement for relevant local 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%2F41527&comment_hash=4fa62bbed8e7591920fb2112d2a8e5605113bc70786bbbadaa7042b1c68b010f&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41527&comment_hash=4fa62bbed8e7591920fb2112d2a8e5605113bc70786bbbadaa7042b1c68b010f&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