Skip to content

Commit

Permalink
Can't use resource with use_cache=False
Browse files Browse the repository at this point in the history
  • Loading branch information
yakimka committed Apr 21, 2024
1 parent c75a2bc commit 9b38357
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nanodi/nanodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@


def Depends(dependency: Dependency, /, use_cache: bool = True) -> Any: # noqa: N802
if dependency in _resources and not use_cache:
raise ValueError("use_cache=False is not supported for resources")
return _Depends(dependency, use_cache)


Expand Down
10 changes: 10 additions & 0 deletions tests/test_sync_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,13 @@ def my_service(redis: Redis = Depends(redis_dependency)):

shutdown_resources()
assert redis.closed is True


def test_resources_cant_be_used_if_specified_without_cache(redis_dependency):
with pytest.raises(
ValueError, match="use_cache=False is not supported for resources"
):

@inject
def my_service(redis1: Redis = Depends(redis_dependency, use_cache=False)):
return redis1

0 comments on commit 9b38357

Please sign in to comment.