Skip to content

[Bug] Update Pydantic converter example to reflect with_child_unrestricted changes #126

Open

Description

@gregbrowndev

What are you really trying to do?

I want to use Pydantic and datetime objects as input/outputs/signals/queries to workflows and activities.

Describe the bug

The recommended reference example for the Pydantic converter creates a new sandbox to work around a bug in Pydantic.

There is a TODO in the code below:

https://github.com/temporalio/samples-python/blob/main/pydantic_converter/worker.py

that says:

TODO(cretz): Use with_child_unrestricted when temporalio/sdk-python#254 is fixed and released

The issue in question has now been merged but the example hasn't been updated.

Minimal Reproduction

https://github.com/temporalio/samples-python/blob/main/pydantic_converter/worker.py

Environment/Versions

n/a

Additional context

n/a

Thanks!

Activity

  1. cretz commented on Jun 18, 2024

    @cretz
    Contributor

    Thanks! Agreed we can now perform that TODO.

  2. baegmon commented on Jul 7, 2024

    @baegmon

    Any update on this one? Currently I'm using Pydantic v2 models with:

    from pydantic_core import to_jsonable_python

    and

    workflow_runner=SandboxedWorkflowRunner(
        restrictions=SandboxRestrictions.default.with_passthrough_modules(
            "pydantic",
        )
    )
    

    Would love to see an example without seeing warnings from https://github.com/temporalio/sdk-python/blob/main/temporalio/converter.py#L561

  3. cretz commented on Jul 8, 2024

    @cretz
    Contributor

    That warning is unrelated to this issue. This issue is simply changing how the sandbox is created. That warning is because presumably you are not using a custom converter like https://github.com/temporalio/samples-python/blob/main/pydantic_converter/converter.py and configuring it on the client.

  4. baegmon commented on Jul 9, 2024

    @baegmon

    That warning is unrelated to this issue. This issue is simply changing how the sandbox is created. That warning is because presumably you are not using a custom converter like https://github.com/temporalio/samples-python/blob/main/pydantic_converter/converter.py and configuring it on the client.

    I've tried that example actually, with just one difference which is using from pydantic_core import to_jsonable_python over pydantic_encoder for v2 on the converter: https://github.com/temporalio/samples-python/blob/main/pydantic_converter/converter.py#L32

    I am still getting the issue on temporalio==1.6.0, do you not get this error?
    This is just on a default python 3.12 devcontainer.

  5. cretz commented on Jul 9, 2024

    @cretz
    Contributor

    We have not tested or created a sample for v2. There is a separate issue at #97 for that. But I think the issue to resolve this unrelated TODO for v1 is unrelated to your issue.

    (also transferring this issue to the samples repo since it doesn't belong in primary repo)

  6. transferred this issue fromtemporalio/sdk-pythonon Jul 9, 2024
  7. dandavison commented on Apr 9, 2025

    @dandavison
    Contributor

    Update: the SDK now contains official Pydantic v2 support, which supports datetime and many other field types, and the sample has been updated. This is the sample to follow for Pydantic v2: https://github.com/temporalio/samples-python/tree/main/pydantic_converter. The old pydantic v1 sample is still in the repo, but if at all possible please use pydantic v2 with the official SDK support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions