Skip to content

Commit

Permalink
fix(dependencies): only set default dependency_cache if it is None
Browse files Browse the repository at this point in the history
This solves a bug where an empty dictionary would be reassigned.
  • Loading branch information
xkabylgSICKAG committed Mar 21, 2024
1 parent 46e99a8 commit 1697c05
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions fastapi/dependencies/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ async def solve_dependencies(
response = Response()
del response.headers["content-length"]
response.status_code = None # type: ignore
dependency_cache = dependency_cache or {}
if dependency_cache is None:
dependency_cache = {}
sub_dependant: Dependant
for sub_dependant in dependant.dependencies:
sub_dependant.call = cast(Callable[..., Any], sub_dependant.call)
Expand Down Expand Up @@ -588,10 +589,8 @@ async def solve_dependencies(
sub_values,
sub_errors,
background_tasks,
_, # the subdependency returns the same response we have
sub_dependency_cache,
*_, # the subdependency returns the same response and cache we already have
) = solved_result
dependency_cache.update(sub_dependency_cache)
if sub_errors:
errors.extend(sub_errors)
continue
Expand Down

0 comments on commit 1697c05

Please sign in to comment.