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
22 changes: 13 additions & 9 deletions python/restate/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,19 @@ def compute_discovery(endpoint: RestateEndpoint, discovered_as: typing.Literal["
description=handler.description,
metadata=handler.metadata,
inactivityTimeout=int(handler.inactivity_timeout.total_seconds() * 1000)
if handler.inactivity_timeout
if handler.inactivity_timeout is not None
else None,
abortTimeout=int(handler.abort_timeout.total_seconds() * 1000)
if handler.abort_timeout is not None
else None,
abortTimeout=int(handler.abort_timeout.total_seconds() * 1000) if handler.abort_timeout else None,
journalRetention=int(handler.journal_retention.total_seconds() * 1000)
if handler.journal_retention
if handler.journal_retention is not None
else None,
idempotencyRetention=int(handler.idempotency_retention.total_seconds() * 1000)
if handler.idempotency_retention
if handler.idempotency_retention is not None
else None,
workflowCompletionRetention=int(handler.workflow_retention.total_seconds() * 1000)
if handler.workflow_retention
if handler.workflow_retention is not None
else None,
enableLazyState=handler.enable_lazy_state,
ingressPrivate=handler.ingress_private,
Expand Down Expand Up @@ -394,14 +396,16 @@ def compute_discovery(endpoint: RestateEndpoint, discovered_as: typing.Literal["
description=description,
metadata=metadata,
inactivityTimeout=int(service.inactivity_timeout.total_seconds() * 1000)
if service.inactivity_timeout
if service.inactivity_timeout is not None
else None,
abortTimeout=int(service.abort_timeout.total_seconds() * 1000)
if service.abort_timeout is not None
else None,
abortTimeout=int(service.abort_timeout.total_seconds() * 1000) if service.abort_timeout else None,
journalRetention=int(service.journal_retention.total_seconds() * 1000)
if service.journal_retention
if service.journal_retention is not None
else None,
idempotencyRetention=int(service.idempotency_retention.total_seconds() * 1000)
if service.idempotency_retention
if service.idempotency_retention is not None
else None,
enableLazyState=service.enable_lazy_state if isinstance(service, (Workflow, VirtualObject)) else None,
ingressPrivate=service.ingress_private,
Expand Down
57 changes: 57 additions & 0 deletions tests/discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# Copyright (c) 2023-2026 - Restate Software, Inc., Restate GmbH
#
# This file is part of the Restate SDK for Python,
# which is released under the MIT license.
#
# You can find a copy of the license in file LICENSE in the root
# directory of this repository or package, or at
# https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
#
from datetime import timedelta

import restate
from restate.discovery import compute_discovery
from restate.endpoint import Endpoint


def test_zero_durations_are_preserved_in_manifest():
service = restate.Service(
"ZeroDurationService",
inactivity_timeout=timedelta(0),
abort_timeout=timedelta(0),
journal_retention=timedelta(0),
idempotency_retention=timedelta(0),
)

@service.handler(
inactivity_timeout=timedelta(0),
abort_timeout=timedelta(0),
journal_retention=timedelta(0),
idempotency_retention=timedelta(0),
)
async def handle(ctx: restate.Context):
pass

workflow = restate.Workflow("ZeroRetentionWorkflow")

@workflow.main(workflow_retention=timedelta(0))
async def run(ctx: restate.WorkflowContext):
pass

manifest = compute_discovery(Endpoint().bind(service, workflow), "bidi")

service_manifest = manifest.services[0]
assert service_manifest.inactivityTimeout == 0
assert service_manifest.abortTimeout == 0
assert service_manifest.journalRetention == 0
assert service_manifest.idempotencyRetention == 0

handler_manifest = service_manifest.handlers[0]
assert handler_manifest.inactivityTimeout == 0
assert handler_manifest.abortTimeout == 0
assert handler_manifest.journalRetention == 0
assert handler_manifest.idempotencyRetention == 0

workflow_handler_manifest = manifest.services[1].handlers[0]
assert workflow_handler_manifest.workflowCompletionRetention == 0
Loading