igorbenav / fastcrud

FastCRUD is a Python package for FastAPI, offering robust async CRUD operations and flexible endpoint creation utilities.
MIT License
530 stars 32 forks source link

Dependencies #70

Closed igorbenav closed 1 month ago

igorbenav commented 1 month ago

closes #53

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (b3f1060) to head (943cbe3).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #70 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 64 64 Lines 4450 4460 +10 ========================================= + Hits 4450 4460 +10 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

JakNowy commented 1 month ago

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

igorbenav commented 1 month ago

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

igorbenav commented 1 month ago

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