Datetime is not json serializable

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()

Hi

I believe you have to use a Pydantic data converter GitHub - temporalio/sdk-python: Temporal Python SDK

page not found: https://github.com/temporalio/samples-python/tree/main/pydantic_converter/v1

ah, this is what i needed since we’re currently pinned to v2 samples-python/pydantic_converter_v1 at main · temporalio/samples-python · GitHub