any ideas how to support datetime objects in python? normally I just use @dataclass_json to serialize properly, but that isn’t working with temporal.
from dataclasses import dataclass
from dataclasses_json import dataclass_json
from datetime import datetime
@dataclass_json
@dataclass
class TestJson:
datetime: datetime = field(default_factory=lambda: datetime.now())
name: str = field(default=‘test’)
@workflow.defn
class TestJsonWorkflow:
@workflow.run
async def run(self) → TestJson:
return TestJson()
will throw: TypeError: Object of type datetime is not JSON serializable
@pytest.mark.asyncio
async def test_json_test_workflow(client: Client):
task_queue = 'test-json-test'
async with Worker(
client,
task_queue=task_queue,
workflows=[TestJsonWorkflow],
):
handle = await client.start_workflow(
TestJsonWorkflow.run,
execution_timeout=timedelta(seconds=1),
id=str(uuid.uuid4()),
task_queue=task_queue,
)
result = await handle.result()
assert result.name == "test"
assert result.datetime < datetime.now()