maranafaamen opened a new issue, #40501:
URL: https://github.com/apache/superset/issues/40501

   ### Bug description
   
   # Relative Time Comparison Offset Regression
   
   ## Bug Description
   
   In Superset 5.0, the offset query used a shifted outer time range, but kept
   `inner_from_dttm` / `inner_to_dttm` aligned with the original selected 
period.
   This preserved the shape of a partial period when comparing on a coarse time
   grain.
   
   In Superset 6.1, for relative offsets, `inner_from_dttm` / `inner_to_dttm` 
are
   set to the shifted range as well. This causes time comparison queries with
   coarse time grains, such as `month`, to include the full shifted bucket 
instead
   of the equivalent partial period.
   
   ## Example
   
   - Current range: `2026-05-01 : 2026-05-28`
   - Time grain: `month`
   - Time comparison offset: `365 days ago`
   - `DATE_RANGE_TIMESHIFTS_ENABLED`: `False`
   
   Expected comparison period:
   
   ```text
   2025-05-01 : 2025-05-28
   ```
   
   Actual behavior in Superset 6.1:
   
   ```text
   2025-05-01 : 2025-05-31
   ```
   
   The comparison may include the full May 2025 month bucket, effectively
   `2025-05-01 : 2025-05-31`. This makes month-level comparisons incorrect for
   incomplete current periods.
   
   ## How To Reproduce
   
   1. Make sure date range timeshifts are disabled:
   
   ```python
   FEATURE_FLAGS = {
       "DATE_RANGE_TIMESHIFTS_ENABLED": False,
   }
   ```
   
   2. Create a time series chart or table chart with a temporal column.
   3. Select a time range that ends before the end of a coarse bucket, for 
example:
   
   ```text
   2026-05-01 : 2026-05-28
   ```
   
   4. Set time grain to `month`.
   5. Enable time comparison with a relative offset:
   
   ```text
   365 days ago
   ```
   
   6. Compare the generated SQL / query object behavior between Superset 5.0 and
      6.1, or compare the resulting metric values against a manual query
      constrained to:
   
   ```text
   2025-05-01 : 2025-05-28
   ```
   
   ## Expected Results
   
   The comparison query should preserve the partial-period shape of the original
   selected range.
   
   For `2026-05-01 : 2026-05-28` with `365 days ago`, the comparison should use
   only:
   
   ```text
   2025-05-01 : 2025-05-28
   ```
   
   The month bucket should not include dates after `2025-05-28`.
   
   ## Actual Results
   
   In Superset 6.1, relative offset processing sets the inner bounds to the 
shifted
   range:
   
   ```python
   query_object_clone.inner_from_dttm = query_object_clone.from_dttm
   query_object_clone.inner_to_dttm = query_object_clone.to_dttm
   ```
   
   As a result, for coarse grains like `month`, the comparison can aggregate the
   full shifted bucket, for example all of May 2025, instead of only May 1-28,
   2025.
   
   ## Why This Matters
   
   This produces incorrect comparisons for dashboards that show month-to-date,
   quarter-to-date, or other incomplete coarse-grain periods.
   
   For example, a month-to-date chart for May 1-28, 2026 compared to
   `365 days ago` should compare against May 1-28, 2025. Comparing against the 
full
   May 2025 month overstates the historical comparison value and makes
   YoY/month-to-date metrics wrong.
   
   ## Regression
   
   This appears to be a regression from Superset 5.0 behavior.
   
   In Superset 5.0, relative time comparison offset processing shifted the outer
   query range but kept the inner bounds based on the original selected period:
   
   ```python
   query_object_clone.from_dttm = get_past_or_future(offset, outer_from_dttm)
   query_object_clone.to_dttm = get_past_or_future(offset, outer_to_dttm)
   
   query_object_clone.inner_from_dttm = outer_from_dttm
   query_object_clone.inner_to_dttm = outer_to_dttm
   ```
   
   In Superset 6.1, the relative offset logic sets `inner_*` to the shifted 
bounds:
   
   ```python
   query_object_clone.from_dttm = get_past_or_future(offset, outer_from_dttm)
   query_object_clone.to_dttm = get_past_or_future(offset, outer_to_dttm)
   
   query_object_clone.inner_from_dttm = query_object_clone.from_dttm
   query_object_clone.inner_to_dttm = query_object_clone.to_dttm
   ```
   
   This changes the semantics of relative time comparison offsets.
   
   ### Screenshots/recordings
   
   <img width="1680" height="771" alt="Image" 
src="https://github.com/user-attachments/assets/6a63c74e-c564-4181-856b-6286824ab19c";
 />
   
   ### Superset version
   
   master / latest-dev
   
   ### Python version
   
   Not applicable
   
   ### Node version
   
   I don't know
   
   ### Browser
   
   Firefox
   
   ### Additional context
   
   This happens with date range timeshifts feature flag disabled:
   
   ```python
   FEATURE_FLAGS = {
       "DATE_RANGE_TIMESHIFTS_ENABLED": False,
   }
   ```
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [x] I have checked Superset's logs for errors and if I found a relevant 
Python stacktrace, I included it here as text in the "additional context" 
section.


-- 
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