rebenitez1802 commented on code in PR #45557:
URL: https://github.com/apache/superset/pull/45557#discussion_r4461500187


##########
superset/connectors/sqla/partition_mapping.py:
##########
@@ -3803,10 +3803,15 @@ def _temporal_literal_sql(partition_column: 
TableColumn, value: date) -> str | N
     rendered = spec.convert_dttm(column_type, instant, db_extra=db_extra)
     if rendered is None:
         return None
-    days_only = holds_days_only(partition_column)
-    if not days_only and rendered == spec.convert_dttm(
-        column_type, instant - timedelta(microseconds=1), db_extra=db_extra
-    ):
+    if holds_days_only(partition_column):
+        return rendered
+    try:
+        earlier = instant - timedelta(microseconds=1)
+    except OverflowError:
+        # `datetime.min` (psycopg2's '-infinity') has no earlier instant to
+        # compare against, so the literal's precision cannot be confirmed.
+        return None

Review Comment:
   🟡 Medium — Existing on master (follow-up, not this PR): other year-1 / 
year-9999 dates still fail the chart
   Same class of bug as this guard, but it sits in 
`superset/models/helpers.py`, outside this diff, so it can't be an applyable 
suggestion. The grain widening and `_round_bounds_outward` in 
`_collect_partition_mirror_range`, and `_round_bound_outward` in 
`_mirror_probe_input`, run outside the fail-open `try` in 
`_build_partition_mirror_predicates`. With `PARTITION_FILTER_MAPPING` on, a 
chart on a mapped dataset fails on:
   - `TEMPORAL_RANGE "2026-01-01 : 9999-12-31"` with grain P1M: `ValueError: 
year 10000 is out of range` (P1D raises `OverflowError`).
   - An end of `9999-12-31 12:00` on a DATE key, or `<= 9999-12-31T23:59:59.5` 
on SQLite: `OverflowError`.
   
   The same charts render with the flag off. Fix: decline the bound when the 
arithmetic leaves the calendar. I checked this on current master: all four 
cases then build the query unpruned, a normal range still mirrors, and the 
partition-mapping suites pass.
   
   ```python
       # _collect_partition_mirror_range: wrap the widening and the rounding
           try:
               if widen_bounds_by is not None:
                   if start_dttm is not None:
                       start_dttm -= widen_bounds_by
                   if end_dttm is not None:
                       end_dttm += widen_bounds_by
   
               # Then round outward, to whatever the engine's literal resolves 
to.
               start_dttm, end_dttm = self._round_bounds_outward(
                   start_dttm, end_dttm, mapped_col
               )
           except (OverflowError, ValueError):
               # A bound pushed past the calendar's edge (an open end typed as
               # 9999-12-31, say) has no wider value to write, so the range is 
not
               # mirrored: the query stays correct and only loses its pruning.
               return
   
       # _mirror_probe_input: wrap the operator dispatch
           try:
               if operator in LOWER_BOUND_OPERATORS:
                   instant = self._round_bound_outward(parsed, col, 
is_upper=False)
               elif operator in UPPER_BOUND_OPERATORS:
                   instant = self._round_bound_outward(parsed, col, 
is_upper=True)
               elif self._literal_is_coarser_than(parsed, col):
                   return _UNMIRRORABLE
               else:
                   instant = parsed
           except (OverflowError, ValueError):
               # Rounded past the calendar's edge, so there is no wider bound.
               return _UNMIRRORABLE
   ```



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