Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ ignore = [
# Typing migration requires runtime annotation compatibility review:
# https://github.com/microsoft/durabletask-python/issues/322
"UP006", "UP007", "UP035", "UP037", "UP040", "UP043", "UP045", "UP047",
# Repository-wide UTC alias cleanup:
# https://github.com/microsoft/durabletask-python/issues/323
"UP017",
]

[tool.ruff.lint.per-file-ignores]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import asyncio
import json
import logging
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta
from typing import Any

import azure.functions as func
Expand Down Expand Up @@ -246,7 +246,7 @@ async def signal_entity(
signal_time = None
delay_seconds = body.get("delay_seconds")
if delay_seconds:
signal_time = datetime.now(timezone.utc) + timedelta(seconds=float(delay_seconds))
signal_time = datetime.now(UTC) + timedelta(seconds=float(delay_seconds))
await client.signal_entity(
entity_id, req.route_params["op"], input=body.get("input"), signal_time=signal_time)
return func.HttpResponse(status_code=202)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import json
import tempfile
from collections.abc import Mapping
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta
from pathlib import Path
from typing import Any, Optional

Expand Down Expand Up @@ -111,7 +111,7 @@ async def start_export(
req: func.HttpRequest, client: df.DurableFunctionsClient) -> func.HttpResponse:
body = req.get_json() or {}
export = _export_client(client)
now = datetime.now(timezone.utc)
now = datetime.now(UTC)
# Callers can narrow the completed-time window so an export only covers the
# instances they just produced (rather than every terminal instance in the
# last hour, which would make the fan-out unbounded).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

import time
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta
from pathlib import Path

import pytest
Expand All @@ -23,7 +23,7 @@ def test_history_export_batch(dtask_app):
# Scope the export to instances completed from just before this test, so the
# fan-out only covers the instances we create here (not every terminal
# instance produced by the wider session).
completed_from = (datetime.now(timezone.utc) - timedelta(seconds=5)).isoformat()
completed_from = (datetime.now(UTC) - timedelta(seconds=5)).isoformat()

# Produce a couple of terminal orchestrations to export.
instance_ids = []
Expand Down
4 changes: 2 additions & 2 deletions tests/azure-functions-durable/e2e/test_v1_client_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
``wait_for_completion_or_create_check_status_response``, and ``rewind``.
"""

from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta

import pytest

Expand Down Expand Up @@ -67,7 +67,7 @@ def test_get_status_by_runtime_status(v1_app):


def test_purge_instance_history_by(v1_app):
created_from = (datetime.now(timezone.utc) - timedelta(minutes=1)).isoformat()
created_from = (datetime.now(UTC) - timedelta(minutes=1)).isoformat()
instance_id = v1_app.start_orchestration("activity_chain")
v1_app.wait_for_completion(instance_id)

Expand Down
16 changes: 8 additions & 8 deletions tests/azure-functions-durable/test_client_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import json
import pickle
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta
from types import SimpleNamespace
from unittest.mock import AsyncMock, Mock, patch

Expand Down Expand Up @@ -216,7 +216,7 @@ def test_history_preserves_unrelated_or_malformed_envelopes(monkeypatch, payload
elif invalid == "signal":
envelope["signal"] = "false"
request = dt_history.EventSentEvent(
event_id=1, timestamp=datetime.now(timezone.utc),
event_id=1, timestamp=datetime.now(UTC),
instance_id="ordinary-instance" if invalid == "target" else "@counter@one",
name="application-event" if invalid == "name" else "op",
input="not-json" if invalid == "json" else json.dumps(envelope))
Expand All @@ -235,7 +235,7 @@ def test_history_hydrates_signals_without_correlating_replies(monkeypatch, paylo
token = json.dumps(store.upload(b'{"reference":"blob:v1:test-container:literal"}'))
request_id = "63c281d7-02d7-412c-9f66-1d6d26a83948"
request = dt_history.EventSentEvent(
event_id=1, timestamp=datetime.now(timezone.utc), instance_id="@counter@one", name=name,
event_id=1, timestamp=datetime.now(UTC), instance_id="@counter@one", name=name,
input=json.dumps({"id": request_id, "op": "set", "signal": True, "input": token}))
reply = dt_history.EventRaisedEvent(
event_id=2, timestamp=request.timestamp, name=request_id,
Expand Down Expand Up @@ -724,8 +724,8 @@ def _make_terminal_state(
return SimpleNamespace(
name="orch",
instance_id="abc",
created_at=datetime(2026, 1, 1, tzinfo=timezone.utc),
last_updated_at=datetime(2026, 1, 1, tzinfo=timezone.utc),
created_at=datetime(2026, 1, 1, tzinfo=UTC),
last_updated_at=datetime(2026, 1, 1, tzinfo=UTC),
runtime_status=runtime_status,
serialized_input=None,
serialized_output=serialized_output,
Expand Down Expand Up @@ -985,8 +985,8 @@ def _fake_state(
return SimpleNamespace(
name="orch",
instance_id="abc",
created_at=datetime(2026, 1, 1, tzinfo=timezone.utc),
last_updated_at=datetime(2026, 1, 2, tzinfo=timezone.utc),
created_at=datetime(2026, 1, 1, tzinfo=UTC),
last_updated_at=datetime(2026, 1, 2, tzinfo=UTC),
runtime_status=runtime_status,
serialized_input='{"in": 1}',
serialized_output=serialized_output,
Expand Down Expand Up @@ -1086,7 +1086,7 @@ async def test_get_status_missing_instance_is_falsy():


def _fake_history():
started_at = datetime(2026, 1, 1, tzinfo=timezone.utc)
started_at = datetime(2026, 1, 1, tzinfo=UTC)
return [
dt_history.OrchestratorStartedEvent(
event_id=-1, timestamp=started_at),
Expand Down
10 changes: 5 additions & 5 deletions tests/azure-functions-durable/test_client_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import json
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timezone
from datetime import UTC, datetime
from unittest.mock import AsyncMock, Mock, patch

import grpc
Expand Down Expand Up @@ -107,8 +107,8 @@ async def test_functions_client_reaches_grpc_server_with_url_path(local_grpc_ser
])
async def test_functions_query_limits_page_size_without_changing_query(use_async, page_size, expected):
query = OrchestrationQuery(
created_time_from=datetime(2026, 1, 1, tzinfo=timezone.utc),
created_time_to=datetime(2026, 2, 1, tzinfo=timezone.utc),
created_time_from=datetime(2026, 1, 1, tzinfo=UTC),
created_time_to=datetime(2026, 2, 1, tzinfo=UTC),
runtime_status=[OrchestrationStatus.RUNNING],
max_instance_count=page_size,
fetch_inputs_and_outputs=True,
Expand All @@ -134,8 +134,8 @@ async def test_functions_query_limits_page_size_without_changing_query(use_async
assert request.instanceIdPrefix.value == "prefix"
assert list(request.runtimeStatus) == [pb.ORCHESTRATION_STATUS_RUNNING]
assert [hub.value for hub in request.taskHubNames] == ["TestHub"]
assert request.createdTimeFrom.ToDatetime(timezone.utc) == query.created_time_from
assert request.createdTimeTo.ToDatetime(timezone.utc) == query.created_time_to
assert request.createdTimeFrom.ToDatetime(UTC) == query.created_time_from
assert request.createdTimeTo.ToDatetime(UTC) == query.created_time_to
assert query.max_instance_count == page_size
finally:
if use_async:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
falsy/empty behaviour for a non-existent instance.
"""

from datetime import datetime, timezone
from datetime import UTC, datetime
from types import SimpleNamespace

import azure.durable_functions as df
Expand Down Expand Up @@ -39,8 +39,8 @@ def test_from_json_reconstructs_attribute_surface():
assert bool(status) is True
assert status.name == "orch"
assert status.instance_id == "abc"
assert status.created_time == datetime(2026, 1, 1, tzinfo=timezone.utc)
assert status.last_updated_time == datetime(2026, 1, 2, tzinfo=timezone.utc)
assert status.created_time == datetime(2026, 1, 1, tzinfo=UTC)
assert status.last_updated_time == datetime(2026, 1, 2, tzinfo=UTC)
assert status.input_ == {"in": 1}
assert status.output == {"out": 2}
assert status.custom_status == "cs"
Expand Down
4 changes: 2 additions & 2 deletions tests/azure-functions-durable/test_entity_testing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Unit tests for host-free durable entity execution."""

from datetime import datetime, timezone
from datetime import UTC, datetime
from typing import Any

import pytest
Expand Down Expand Up @@ -105,7 +105,7 @@ def reset(self) -> str:


def test_execute_entity_returns_typed_actions():
signal_time = datetime(2030, 1, 2, 3, 4, tzinfo=timezone.utc)
signal_time = datetime(2030, 1, 2, 3, 4, tzinfo=UTC)

class Relay(DurableEntity):
def dispatch(self, input: dict[str, Any]) -> str:
Expand Down
10 changes: 5 additions & 5 deletions tests/azure-functions-durable/test_history_export_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from __future__ import annotations

from datetime import datetime, timezone
from datetime import UTC, datetime
from types import SimpleNamespace
from unittest.mock import MagicMock

Expand All @@ -29,7 +29,7 @@
import azure.durable_functions.internal.history_export_compat as hec

_FROM = "2025-01-01T00:00:00+00:00"
_COMPLETED = datetime(2026, 1, 1, tzinfo=timezone.utc)
_COMPLETED = datetime(2026, 1, 1, tzinfo=UTC)


def _state(instance_id: str, completed_at: datetime = _COMPLETED) -> SimpleNamespace:
Expand Down Expand Up @@ -89,8 +89,8 @@ def test_exact_multiple_of_page_size_terminates():


def test_completed_time_window_is_applied():
early = datetime(2020, 1, 1, tzinfo=timezone.utc)
late = datetime(2030, 1, 1, tzinfo=timezone.utc)
early = datetime(2020, 1, 1, tzinfo=UTC)
late = datetime(2030, 1, 1, tzinfo=UTC)
ctx = _context_with_states([
_state("early", early), _state("in-window", _COMPLETED), _state("late", late)])
page = hec.list_terminal_instances(ctx, {
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_continuous_create_over_active_job_is_rejected_and_preserves_state():
config=ExportJobCreationOptions(
mode=ExportMode.BATCH,
completed_time_from=_COMPLETED,
completed_time_to=datetime(2026, 1, 2, tzinfo=timezone.utc),
completed_time_to=datetime(2026, 1, 2, tzinfo=UTC),
destination=ExportDestination(container="exports", prefix="run-1"),
).to_configuration(),
created_at=_COMPLETED,
Expand Down
6 changes: 3 additions & 3 deletions tests/azure-functions-durable/test_http_builtin_compat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta
from types import SimpleNamespace
from unittest.mock import MagicMock, patch
import urllib.error
Expand Down Expand Up @@ -264,7 +264,7 @@ def create_timer(fire_at):
get_input=lambda: request,
call_activity=call_activity,
create_timer=create_timer,
current_utc_datetime=datetime(2020, 1, 1, tzinfo=timezone.utc),
current_utc_datetime=datetime(2020, 1, 1, tzinfo=UTC),
parent_instance_id=parent_instance_id,
_activity_calls=activity_calls,
)
Expand Down Expand Up @@ -419,7 +419,7 @@ def test_poll_orchestrator_resolves_relative_location():
# Retry-After parsing
# ---------------------------------------------------------------------------

_NOW = datetime(2020, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
_NOW = datetime(2020, 1, 1, 0, 0, 0, tzinfo=UTC)


def test_retry_after_delta_seconds():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

from datetime import datetime, timezone
from datetime import UTC, datetime
import os
import time

Expand Down Expand Up @@ -67,7 +67,7 @@ def do_nothing(self, _):
assert state is not None
assert state.id == entity_id
assert state.get_locked_by() is None
assert state.last_modified < datetime.now(timezone.utc)
assert state.last_modified < datetime.now(UTC)
assert state.get_state(int) == 1

assert invoked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import threading
import time
import uuid
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta

import pytest

Expand All @@ -33,7 +33,7 @@ def __init__(self):

def record(self) -> None:
with self._lock:
self.times.append(datetime.now(timezone.utc))
self.times.append(datetime.now(UTC))

@property
def count(self) -> int:
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_client_delayed_signal_is_deferred():
c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=secure_channel,
taskhub=taskhub_name, token_credential=None)
entity_id = entities.EntityInstanceId("Recorder", f"client-delay-{uuid.uuid4().hex[:8]}")
sent_at = datetime.now(timezone.utc)
sent_at = datetime.now(UTC)
c.signal_entity(entity_id, "ping", signal_time=sent_at + timedelta(seconds=4))

time.sleep(1)
Expand All @@ -96,7 +96,7 @@ def signaling_orchestrator(ctx: task.OrchestrationContext, key: str):
c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=secure_channel,
taskhub=taskhub_name, token_credential=None)
key = f"orch-delay-{uuid.uuid4().hex[:8]}"
sent_at = datetime.now(timezone.utc)
sent_at = datetime.now(UTC)
instance_id = c.schedule_new_orchestration(signaling_orchestrator, input=key)
c.wait_for_orchestration_completion(instance_id, timeout=30)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

from datetime import datetime, timezone
from datetime import UTC, datetime
import os
import time

Expand Down Expand Up @@ -67,7 +67,7 @@ def empty_entity(ctx: entities.EntityContext, _):
assert state is not None
assert state.id == entity_id
assert state.get_locked_by() is None
assert state.last_modified < datetime.now(timezone.utc)
assert state.last_modified < datetime.now(UTC)
assert state.get_state(int) == 1

assert invoked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import threading
import time
import uuid
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta

import pytest

Expand Down Expand Up @@ -93,7 +93,7 @@ def test_create_describe_and_run():
orchestration_name=task.get_name(target_orchestrator),
interval=timedelta(seconds=1),
orchestration_input="hello",
start_at=datetime.now(timezone.utc),
start_at=datetime.now(UTC),
start_immediately_if_late=True,
))
try:
Expand All @@ -117,7 +117,7 @@ def test_pause_and_resume():
schedule_id=schedule_id,
orchestration_name=task.get_name(target_orchestrator),
interval=timedelta(seconds=1),
start_at=datetime.now(timezone.utc),
start_at=datetime.now(UTC),
start_immediately_if_late=True,
))
try:
Expand Down Expand Up @@ -149,7 +149,7 @@ def test_update_interval_and_input():
orchestration_name=task.get_name(target_orchestrator),
interval=timedelta(seconds=30),
orchestration_input="before",
start_at=datetime.now(timezone.utc) + timedelta(hours=1),
start_at=datetime.now(UTC) + timedelta(hours=1),
))
try:
schedule.update(ScheduleUpdateOptions(
Expand Down Expand Up @@ -177,7 +177,7 @@ def test_list_and_delete():
schedule_id=schedule_id,
orchestration_name=task.get_name(target_orchestrator),
interval=timedelta(seconds=30),
start_at=datetime.now(timezone.utc) + timedelta(hours=1),
start_at=datetime.now(UTC) + timedelta(hours=1),
))
created.append(schedule_id)

Expand Down
Loading
Loading