Skip to content

ResponseModel is not fully defined #164

@keviddles

Description

@keviddles

I'm running into an issue when returning a class as a return type.

Omitting the return type works great:

from ..config import Config

def get_config():
    return Config()

Specifying an explicit return type works great:

from ..config import Config

def get_config() -> Config:
    return Config()

Specifying the type under TYPE_CHECKING fails:

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from ..config import Config

def get_config() -> "Config":
    from ..config import Config
    return Config()

It fails with this error:

self = <fast_depends.core.model.CallModel object at 0x1045a8300>
value = Config(...)

    def _cast_response(self, /, value: Any) -> Any:
        if self.response_model is not None:
>           return self.response_model(response=value).response
E           pydantic.errors.PydanticUserError: `ResponseModel` is not fully defined; you should define `Config`, then call `ResponseModel.model_rebuild()`.
E
E           For further information visit https://errors.pydantic.dev/2.10/u/class-not-fully-defined

.venv/lib/python3.12/site-packages/fast_depends/core/model.py:325: PydanticUserError

Is this use case supported?

For my application, config.py does some heavy lifting that I'm trying to mock in my tests, therefore I'm trying to avoid loading it unless the file is explicitly called, but I want to reference the type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions