Skip to content

Task cannot generate pydantic-core schema for methods with TaskiqDepends #491

@kai-nashi

Description

@kai-nashi

taskiq == 0.11.18

import asyncio
from typing import Annotated

from taskiq import Context
from taskiq import TaskiqDepends
from taskiq import InMemoryBroker

broker = InMemoryBroker()


@broker.task("my_task")
async def my_task(context: Annotated[Context, TaskiqDepends()], x: int) -> None:
    print(f'{x=}')


if __name__ == "__main__":
    asyncio.run(my_task.kiq(1))

Expected:

$ x=1

Real:

pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'taskiq.context.Context'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

BUT:

@broker.task("my_task")
async def my_task(x: int, context: Annotated[Context, TaskiqDepends()]) -> None:
    print(f'{x=}')

Will work as expected.

Problem:
When parsing params in https://github.com/taskiq-python/taskiq/blob/master/taskiq/receiver/params_parser.py#L70
Dependency might be ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions