From 44f4c97a93c47d7b0a2c4a91bb576ac947aa8364 Mon Sep 17 00:00:00 2001 From: mrkaye97 Date: Mon, 15 Dec 2025 17:10:12 -0500 Subject: [PATCH] feat: test for dict inputs --- .../examples/dict_input/test_dict_input.py | 55 +++++++++++++++++++ sdks/python/examples/dict_input/worker.py | 16 ++++++ sdks/python/examples/worker.py | 2 + sdks/python/hatchet_sdk/runnables/types.py | 2 +- 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 sdks/python/examples/dict_input/test_dict_input.py create mode 100644 sdks/python/examples/dict_input/worker.py diff --git a/sdks/python/examples/dict_input/test_dict_input.py b/sdks/python/examples/dict_input/test_dict_input.py new file mode 100644 index 000000000..29bb2aed6 --- /dev/null +++ b/sdks/python/examples/dict_input/test_dict_input.py @@ -0,0 +1,55 @@ +import pytest + +from examples.dict_input.worker import Output, say_hello_unsafely + + +@pytest.mark.asyncio(loop_scope="session") +async def test_dict_input() -> None: + input = {"name": "Hatchet"} + + x1 = say_hello_unsafely.run(input) + x2 = await say_hello_unsafely.aio_run(input) + + x3 = say_hello_unsafely.run_many([say_hello_unsafely.create_bulk_run_item(input)])[ + 0 + ] + x4 = ( + await say_hello_unsafely.aio_run_many( + [say_hello_unsafely.create_bulk_run_item(input)] + ) + )[0] + + x5 = say_hello_unsafely.run_no_wait(input).result() + x6 = (await say_hello_unsafely.aio_run_no_wait(input)).result() + x7 = [ + x.result() + for x in say_hello_unsafely.run_many_no_wait( + [say_hello_unsafely.create_bulk_run_item(input)] + ) + ][0] + x8 = [ + x.result() + for x in await say_hello_unsafely.aio_run_many_no_wait( + [say_hello_unsafely.create_bulk_run_item(input)] + ) + ][0] + + x9 = await say_hello_unsafely.run_no_wait(input).aio_result() + x10 = await (await say_hello_unsafely.aio_run_no_wait(input)).aio_result() + x11 = [ + await x.aio_result() + for x in say_hello_unsafely.run_many_no_wait( + [say_hello_unsafely.create_bulk_run_item(input)] + ) + ][0] + x12 = [ + await x.aio_result() + for x in await say_hello_unsafely.aio_run_many_no_wait( + [say_hello_unsafely.create_bulk_run_item(input)] + ) + ][0] + + assert all( + x == Output(message="Hello, Hatchet!") + for x in [x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12] + ) diff --git a/sdks/python/examples/dict_input/worker.py b/sdks/python/examples/dict_input/worker.py new file mode 100644 index 000000000..b33d23390 --- /dev/null +++ b/sdks/python/examples/dict_input/worker.py @@ -0,0 +1,16 @@ +from pydantic import BaseModel + +from hatchet_sdk import Context, Hatchet + + +class Output(BaseModel): + message: str + + +hatchet = Hatchet(debug=True) + + +@hatchet.task(input_validator=dict) +def say_hello_unsafely(input: dict[str, str], _c: Context) -> Output: + name = input["name"] # untyped + return Output(message=f"Hello, {name}!") diff --git a/sdks/python/examples/worker.py b/sdks/python/examples/worker.py index a8679eb34..859bde41c 100644 --- a/sdks/python/examples/worker.py +++ b/sdks/python/examples/worker.py @@ -30,6 +30,7 @@ from examples.dependency_injection.worker import ( durable_sync_task_with_dependencies, sync_task_with_dependencies, ) +from examples.dict_input.worker import say_hello_unsafely from examples.durable.worker import durable_workflow, wait_for_sleep_twice from examples.events.worker import event_workflow from examples.fanout.worker import child_wf, parent_wf @@ -94,6 +95,7 @@ def main() -> None: durable_async_task_with_dependencies, durable_sync_task_with_dependencies, say_hello, + say_hello_unsafely, ], lifespan=lifespan, ) diff --git a/sdks/python/hatchet_sdk/runnables/types.py b/sdks/python/hatchet_sdk/runnables/types.py index 0beda3929..83a81941a 100644 --- a/sdks/python/hatchet_sdk/runnables/types.py +++ b/sdks/python/hatchet_sdk/runnables/types.py @@ -61,7 +61,7 @@ class ConcurrencyExpression(BaseModel): TWorkflowInput = TypeVar( - "TWorkflowInput", bound=BaseModel | DataclassInstance | dict[str, Any] | None + "TWorkflowInput", bound=BaseModel | DataclassInstance | dict[str, Any] )