codeant-ai-for-open-source[bot] commented on code in PR #42269:
URL: https://github.com/apache/superset/pull/42269#discussion_r3622320284
##########
tests/unit_tests/common/test_query_context_processor.py:
##########
@@ -2151,3 +2151,37 @@ def
test_raise_for_access_evaluates_access_before_validate():
processor.raise_for_access()
query.validate.assert_not_called()
+
+
+def test_relative_offset_preserves_inner_bounds():
+ """
+ Regression test for #40501: Relative time comparison offset should
+ preserve inner bounds as the original (unshifted) period, not the shifted
one.
+
+ When comparing 2026-05-01 : 2026-05-28 with offset "365 days ago":
+ - inner_from_dttm should be 2026-05-01 (original), NOT 2025-05-01 (shifted)
+ - inner_to_dttm should be 2026-05-28 (original), NOT 2025-05-28 (shifted)
+ """
+ outer_from = datetime(2026, 5, 1)
+ outer_to = datetime(2026, 5, 28)
+ offset = "365 days ago"
+
+ shifted_from = get_past_or_future(offset, outer_from)
+ shifted_to = get_past_or_future(offset, outer_to)
+
+ # Verify the shifted dates are correct
+ assert shifted_from == datetime(2025, 5, 1)
+ assert shifted_to == datetime(2025, 5, 28)
+
+ # The fix: inner bounds should use original period, not shifted
+ # This ensures partial periods (e.g., May 1-28) compare against
+ # the equivalent partial period in the past, not the full bucket
+ inner_from_dttm = outer_from # Should be original, not shifted_from
+ inner_to_dttm = outer_to # Should be original, not shifted_to
+
+ assert inner_from_dttm == datetime(2026, 5, 1)
+ assert inner_to_dttm == datetime(2026, 5, 28)
+
+ # Verify inner bounds are NOT the shifted values
+ assert inner_from_dttm != shifted_from
+ assert inner_to_dttm != shifted_to
Review Comment:
**Suggestion:** This regression test does not exercise the query context
processing code path at all, so it will pass even if the production bug
returns. It only compares locally assigned variables (`inner_* = outer_*`) and
therefore cannot detect whether comparison query objects preserve inner bounds
correctly. Build the test around the real processor/query-object transformation
and assert on the produced comparison query object's
`inner_from_dttm`/`inner_to_dttm` values. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Regression bug #40501 may reappear undetected.
- ⚠️ CI green even if time comparison breaks.
- ⚠️ Query context processor behavior not covered by this test.
- ⚠️ Developers gain false confidence from tautological regression test.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Open `tests/unit_tests/common/test_query_context_processor.py` and locate
`test_relative_offset_preserves_inner_bounds` at lines 2156–2187.
2. Inspect lines 2179–2187: `inner_from_dttm` and `inner_to_dttm` are
assigned directly
from `outer_from`/`outer_to`, then asserted against literals and compared to
`shifted_*` —
no call is made to any function/class from
`superset.common.query_context_processor` or to
a query object factory.
3. Run `pytest
tests/unit_tests/common/test_query_context_processor.py::test_relative_offset_preserves_inner_bounds`;
observe the test passes purely based on the local variable assignments and
assertions in
this function.
4. Note that the production logic that was bugged (relative time comparison
offset
handling in `superset/common/query_context_processor.py`, referenced
elsewhere in this
file via
`superset.common.query_context_processor.security_manager.raise_for_access` at
lines 2146–2148) is never invoked here, so any future regression in inner
bound handling
would not affect this test and it would still pass.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=4bec08c233b3479e9cae57f336c1a667&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=4bec08c233b3479e9cae57f336c1a667&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/common/test_query_context_processor.py
**Line:** 2179:2187
**Comment:**
*Logic Error: This regression test does not exercise the query context
processing code path at all, so it will pass even if the production bug
returns. It only compares locally assigned variables (`inner_* = outer_*`) and
therefore cannot detect whether comparison query objects preserve inner bounds
correctly. Build the test around the real processor/query-object transformation
and assert on the produced comparison query object's
`inner_from_dttm`/`inner_to_dttm` values.
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%2F42269&comment_hash=1c3113879a4316d22b9f45c48f0a75eacdd99eabf864b4abd868d687a976b1a0&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42269&comment_hash=1c3113879a4316d22b9f45c48f0a75eacdd99eabf864b4abd868d687a976b1a0&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]