Skip to main content

solve_dependencies

Recursively resolves all dependencies for a given request, extracting values from path parameters, query strings, headers, cookies, and the request body. It manages dependency caching, handles overrides, and ensures proper cleanup using asynchronous exit stacks.

def solve_dependencies(
request: Request | WebSocket,
dependant: Dependant,
body: dict[str, Any] | FormData | bytes | None = None,
background_tasks: StarletteBackgroundTasks | None = None,
response: Response | None = None,
dependency_overrides_provider: Any | None = None,
dependency_cache: dict[DependencyCacheKey, Any] | None = None,
async_exit_stack: AsyncExitStack,
embed_body_fields: bool
) - > SolvedDependency

Recursively resolves all dependencies for a given route handler, extracting values from the request and executing dependency functions. It manages the dependency lifecycle, including caching, overrides, and integration with async exit stacks for resource cleanup.

Parameters

NameTypeDescription
request`RequestWebSocket`
dependantDependantThe metadata object defining the hierarchy of dependencies and parameters required by the target function.
body`dict[str, Any]FormData
background_tasks`StarletteBackgroundTasksNone` = None
response`ResponseNone` = None
dependency_overrides_provider`AnyNone` = None
dependency_cache`dict[DependencyCacheKey, Any]None` = None
async_exit_stackAsyncExitStackA legacy parameter maintained for compatibility; the function now primarily uses stacks found within the request scope.
embed_body_fieldsboolA flag indicating whether single body parameters should be expected as embedded JSON fields rather than the root body.

Returns

TypeDescription
SolvedDependencyAn object containing the resolved parameter values, any validation errors encountered, the background tasks instance, and the updated dependency cache.