Lee-W commented on code in PR #67717:
URL: https://github.com/apache/airflow/pull/67717#discussion_r3367768145


##########
airflow-core/src/airflow/cli/commands/dag_command.py:
##########
@@ -157,10 +165,52 @@ def dag_clear(args, *, session: Session = NEW_SESSION) -> 
None:
         query = query.where(DagRun.partition_key == args.partition_key)
     else:
         query = query.where(DagRun.partition_date.is_not(None))
-        if args.partition_date_start is not None:
-            query = query.where(DagRun.partition_date >= 
args.partition_date_start)
-        if args.partition_date_end is not None:
-            query = query.where(DagRun.partition_date <= 
args.partition_date_end)
+        tt_tz = getattr(dag.timetable, "timezone", None) if 
dag.timetable.partitioned else None
+        if tt_tz is not None:
+            # Partitioned runs are stored as local-midnight UTC instants; 
compare at day
+            # granularity in the timetable's timezone rather than at the raw 
UTC instant.
+            if args.partition_date_start is not None:
+                start_label = args.partition_date_start.date()
+                lower_utc = timezone.convert_to_utc(
+                    timezone.make_aware(
+                        datetime.datetime(start_label.year, start_label.month, 
start_label.day),
+                        tt_tz,
+                    )
+                )
+                query = query.where(DagRun.partition_date >= lower_utc)
+            if args.partition_date_end is not None:
+                end_label = args.partition_date_end.date()
+                # Half-open upper bound: include all of the end local calendar 
day.
+                next_day = datetime.date(end_label.year, end_label.month, 
end_label.day) + datetime.timedelta(

Review Comment:
   Removed the redundant `datetime.date(...)` rebuild. The upper bound is now 
just `end.date() + datetime.timedelta(days=1)` and passed into 
`resolve_day_bound`



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

Reply via email to