Skip to content
9 changes: 8 additions & 1 deletion application_sdk/activities/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from datetime import timedelta
from functools import wraps
from typing import Any, Awaitable, Callable, List, Optional, TypeVar, cast
import re

from temporalio import activity

Expand Down Expand Up @@ -71,9 +72,15 @@ def build_output_path() -> str:
>>> build_output_path()
"artifacts/apps/appName/workflows/wf-123/run-456"
"""
# Sanitize workflow_id to remove any schedule/timestamp suffix
raw_workflow_id = get_workflow_id()

# If workflow_id contains a timestamp (e.g., '-YYYY-MM-DDTHH:MM:SSZ'), remove it
sanitized_workflow_id = re.sub(r'-\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$', '', raw_workflow_id)
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern is hardcoded and assumes a specific timestamp format. Consider defining this as a module-level constant with a descriptive name like SCHEDULE_TIMESTAMP_PATTERN to improve maintainability and make the pattern reusable.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex should be compiled once at module level for better performance, especially since this function may be called frequently. Use re.compile() to create a compiled pattern object.

Copilot uses AI. Check for mistakes.

return WORKFLOW_OUTPUT_PATH_TEMPLATE.format(
application_name=APPLICATION_NAME,
workflow_id=get_workflow_id(),
workflow_id=sanitized_workflow_id,
run_id=get_workflow_run_id(),
)

Expand Down
Loading