Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions autobot-backend/workflow_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@
from constants.threshold_constants import RetryConfig, WorkflowConfig


def _ensure_utc_aware(value: datetime) -> datetime:
"""Tag a naive ``datetime`` as UTC; pass tz-aware values through unchanged.

Issue #12453: callers may hand ``schedule_workflow``/``reschedule_workflow``
a naive ``datetime`` (e.g. ``datetime.now()``) instead of an ISO string.
Unlike the string path (``parse_utc_iso``), naive ``datetime`` objects were
never normalized, so later comparisons against tz-aware ``now`` values
(``get_scheduler_status``, ``_process_scheduled_workflows``,
``_calculate_priority_score``) raised
``TypeError: can't compare offset-naive and offset-aware datetimes``.
Matches ``parse_utc_iso``'s "naive is assumed UTC" convention.
"""
if value.tzinfo is None:
return value.replace(tzinfo=timezone.utc)
return value


class WorkflowPriority(Enum):
"""Workflow execution priority levels"""

Expand Down Expand Up @@ -474,6 +491,8 @@ def _parse_schedule_params(
scheduled_time = parse_utc_iso(scheduled_time)
except ValueError:
scheduled_time = self._parse_time_string(scheduled_time)
else:
scheduled_time = _ensure_utc_aware(scheduled_time)

# Parse priority and complexity
if isinstance(priority, str):
Expand Down Expand Up @@ -706,6 +725,8 @@ def reschedule_workflow(
# Parse new time
if isinstance(new_time, str):
new_time = self._parse_time_string(new_time)
else:
new_time = _ensure_utc_aware(new_time)

workflow.scheduled_time = new_time

Expand Down
Loading