pydantic_wrapper
Wrapper to validate arguments and serialize return values using Pydantic.
def pydantic_wrapper(
app: Celery,
task_fun: typing.Callable[..., typing.Any],
task_name: str,
strict: bool = True,
context: typing.Optional[typing.Dict[str, typing.Any]] = null,
dump_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = null
) - > typing.Callable
Wrapper to validate arguments and serialize return values using Pydantic.
Parameters
| Name | Type | Description |
|---|---|---|
| app | Celery | The Celery application instance associated with the task. |
| task_fun | typing.Callable[..., typing.Any] | The original task function to be wrapped and validated. |
| task_name | str | The unique string identifier for the Celery task. |
| strict | bool = True | Whether to use Pydantic's strict mode for model validation. |
| context | typing.Optional[typing.Dict[str, typing.Any]] = null | Additional context data passed to the Pydantic validation process. |
| dump_kwargs | typing.Optional[typing.Dict[str, typing.Any]] = null | Configuration arguments passed to Pydantic's model_dump method during serialization. |
Returns
| Type | Description |
|---|---|
typing.Callable | A wrapped version of the task function that performs Pydantic validation on inputs and serialization on outputs. |