codeant-ai-for-open-source[bot] commented on code in PR #42082: URL: https://github.com/apache/superset/pull/42082#discussion_r3593389771
########## tests/unit_tests/models/test_time_comparison_offset.py: ########## @@ -0,0 +1,84 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Regression test for #40501. + +Time comparisons using a relative offset (e.g. ``'365 days ago'``) on +coarse time grains (``month`` / ``quarter`` / ``year``) previously +snapped the compared bucket to the full grain boundary when the current +period was not fully aligned to the grain. On ``2026-05-01 : +2026-05-28`` with ``month`` grain, the ``365 days ago`` comparison +covered all of May 2025 instead of only the first 28 days. + +Root cause: ``ExploreMixin.processing_time_offsets`` set +``inner_from_dttm`` / ``inner_to_dttm`` to the shifted range in the +relative-offset branch, while the sibling date-range branch left them +unset. The fix aligns the two branches โ both leave inner bounds +``None`` so the downstream subquery uses one WHERE clause on the +shifted outer range instead of layering a second, semantically-different +filter that widened the bucket via the semantic-layer subquery-bounds +path. + +Pinned at the source level because ``processing_time_offsets`` executes +real datasource queries end-to-end โ mocking the full call chain just to +inspect a local variable inside a ~250-line method would be far more +fragile than reading the committed source. +""" + +from __future__ import annotations + +import inspect +import re + +from superset.models.helpers import ExploreMixin + +_SOURCE: str = inspect.getsource(ExploreMixin.processing_time_offsets) + + +def test_relative_offset_leaves_inner_dttm_none() -> None: + """The relative-offset branch must not assign the shifted range to + ``inner_from_dttm`` / ``inner_to_dttm`` โ doing so re-introduces + #40501 (partial-period comparisons snap to the full grain bucket on + coarse time grains). + """ + forbidden_from = re.compile(r"inner_from_dttm\s*=\s*query_object_clone\.from_dttm") Review Comment: **Suggestion:** Add an explicit type annotation for this regex variable to satisfy the type-hint requirement for newly introduced variables. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> This new local variable is introduced without a type annotation, and it is a clearly annotatable Python variable. That matches the type-hint rule for newly 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=437c77251d6b4b14a81acd5b9f56ba5b&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=437c77251d6b4b14a81acd5b9f56ba5b&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/test_time_comparison_offset.py **Line:** 57:57 **Comment:** *Custom Rule: Add an explicit type annotation for this regex variable to satisfy the type-hint requirement for newly introduced 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%2F42082&comment_hash=adf5bc208491f13fe1e1bf1ddbb4dd90fcacd75dfbe80eb60e44c6747c19ba2e&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42082&comment_hash=adf5bc208491f13fe1e1bf1ddbb4dd90fcacd75dfbe80eb60e44c6747c19ba2e&reaction=dislike'>๐</a> ########## tests/unit_tests/models/test_time_comparison_offset.py: ########## @@ -0,0 +1,84 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Regression test for #40501. + +Time comparisons using a relative offset (e.g. ``'365 days ago'``) on +coarse time grains (``month`` / ``quarter`` / ``year``) previously +snapped the compared bucket to the full grain boundary when the current +period was not fully aligned to the grain. On ``2026-05-01 : +2026-05-28`` with ``month`` grain, the ``365 days ago`` comparison +covered all of May 2025 instead of only the first 28 days. + +Root cause: ``ExploreMixin.processing_time_offsets`` set +``inner_from_dttm`` / ``inner_to_dttm`` to the shifted range in the +relative-offset branch, while the sibling date-range branch left them +unset. The fix aligns the two branches โ both leave inner bounds +``None`` so the downstream subquery uses one WHERE clause on the +shifted outer range instead of layering a second, semantically-different +filter that widened the bucket via the semantic-layer subquery-bounds +path. + +Pinned at the source level because ``processing_time_offsets`` executes +real datasource queries end-to-end โ mocking the full call chain just to +inspect a local variable inside a ~250-line method would be far more +fragile than reading the committed source. +""" + +from __future__ import annotations + +import inspect +import re + +from superset.models.helpers import ExploreMixin + +_SOURCE: str = inspect.getsource(ExploreMixin.processing_time_offsets) + + +def test_relative_offset_leaves_inner_dttm_none() -> None: + """The relative-offset branch must not assign the shifted range to + ``inner_from_dttm`` / ``inner_to_dttm`` โ doing so re-introduces + #40501 (partial-period comparisons snap to the full grain bucket on + coarse time grains). + """ + forbidden_from = re.compile(r"inner_from_dttm\s*=\s*query_object_clone\.from_dttm") + forbidden_to = re.compile(r"inner_to_dttm\s*=\s*query_object_clone\.to_dttm") + assert not forbidden_from.search(_SOURCE), ( + "processing_time_offsets assigns inner_from_dttm to the shifted " + "range โ re-introduces #40501. Set to ``None`` instead." + ) + assert not forbidden_to.search(_SOURCE), ( + "processing_time_offsets assigns inner_to_dttm to the shifted " + "range โ re-introduces #40501. Set to ``None`` instead." + ) + + +def test_relative_offset_branch_has_none_assignment() -> None: + """Positive check: both branches (relative + date-range) must + contain explicit ``inner_from_dttm = None`` / ``inner_to_dttm = + None`` assignments so the shifted outer range is used as the sole + time filter. See #40501. + """ + from_none_count = len(re.findall(r"inner_from_dttm\s*=\s*None", _SOURCE)) Review Comment: **Suggestion:** Add an explicit type annotation for this computed counter variable to comply with the type-hint rule. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> This computed integer variable is added without an explicit type annotation, so it violates the rule requiring type hints on new annotatable Python variables. </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=0909f1c007d544cdb639348ee5a739c2&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=0909f1c007d544cdb639348ee5a739c2&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/test_time_comparison_offset.py **Line:** 75:75 **Comment:** *Custom Rule: Add an explicit type annotation for this computed counter variable to comply 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%2F42082&comment_hash=5183d81fee4860581eb601e86d7c31be56845a5ae53fe805d15e9f6a98862402&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42082&comment_hash=5183d81fee4860581eb601e86d7c31be56845a5ae53fe805d15e9f6a98862402&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]
