Closed igorbenav closed 1 month ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 100.00%. Comparing base (
b3f1060
) to head (943cbe3
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I was lucky to track the library development, so I knew exactly what's going on and how to fix it, but this resulted in a breaking change for my app:
"AssertionError: A parameter-less dependency must have a callable dependency
Maybe we could communicate that to users somehow? @igorbenav
Hmm fair point, I'll add a descriptive error if what's passed is already wrapped in Depends explaining that it changed since 0.12.0
Done in #82. Added a warning and we'll support it until 0.15.0
.
Just before 0.15.0 we can just remove this _temporary_dependency_handling
function and the part it's mentioned in _inject_dependencies.
def _temporary_dependency_handling(
funcs: Optional[Sequence[Callable]] = None,
) -> Union[Sequence[params.Depends], None]: # pragma: no cover
"""
Checks if any function in the provided sequence is an instance of params.Depends.
Issues a deprecation warning once if such instances are found, and returns the sequence if any params.Depends are found.
Args:
funcs: Optional sequence of callables or params.Depends instances.
"""
if funcs is not None:
if any(isinstance(func, params.Depends) for func in funcs):
warnings.warn(
"Passing a function wrapped in `Depends` directly to dependency handlers is deprecated and will be removed in version 0.15.0.",
DeprecationWarning,
stacklevel=2,
)
return [
func if isinstance(func, params.Depends) else Depends(func)
for func in funcs
]
return None
def _inject_dependencies(
funcs: Optional[Sequence[Callable]] = None,
) -> Optional[Sequence[params.Depends]]:
"""Wraps a list of functions in FastAPI's Depends."""
temp_handling = _temporary_dependency_handling(funcs)
if temp_handling is not None: # pragma: no cover
return temp_handling
if funcs is not None:
return [Depends(func) for func in funcs]
return None
closes #53