Skip to content

Commit 60c6094

Browse files
committed
Removed unused arg from _resolve_regular_dependency and added test
1 parent ba5b25c commit 60c6094

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

fastopenapi/core/dependency_resolver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def _resolve_single_dependency(
135135

136136
# Handle regular Depends
137137
return self._resolve_regular_dependency(
138-
dependency, dependency_func, request_data, param_name
138+
dependency_func, request_data, param_name
139139
)
140140

141141
def _resolve_security_dependency(
@@ -166,7 +166,6 @@ def _resolve_security_dependency(
166166

167167
def _resolve_regular_dependency(
168168
self,
169-
depends: Depends,
170169
dependency_func: Callable,
171170
request_data: RequestData,
172171
param_name: str,

tests/core/test_dependency_resolver.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,59 @@ def endpoint(dep=Depends(sync_gen)):
16261626
assert result == {"dep": "sync_value"}
16271627
assert cleanup_called
16281628

1629+
def test_sync_generator_cleanup_exception_swallowed(self):
1630+
"""Test that exception in generator's finally block is silently swallowed"""
1631+
cleanup_log = []
1632+
1633+
def failing_cleanup_gen():
1634+
try:
1635+
yield "value"
1636+
finally:
1637+
cleanup_log.append("cleanup_attempted")
1638+
raise RuntimeError("cleanup exploded")
1639+
1640+
def healthy_gen():
1641+
try:
1642+
yield "healthy"
1643+
finally:
1644+
cleanup_log.append("healthy_cleanup")
1645+
1646+
def endpoint(a=Depends(failing_cleanup_gen), b=Depends(healthy_gen)):
1647+
return f"{a}_{b}"
1648+
1649+
result = self.resolver.resolve_dependencies(endpoint, self.request_data)
1650+
assert result == {"a": "value", "b": "healthy"}
1651+
assert "cleanup_attempted" in cleanup_log
1652+
assert "healthy_cleanup" in cleanup_log
1653+
1654+
@pytest.mark.asyncio
1655+
async def test_async_generator_cleanup_exception_swallowed(self):
1656+
"""Test that async generator cleanup exception is silently swallowed"""
1657+
cleanup_log = []
1658+
1659+
async def failing_cleanup_gen():
1660+
try:
1661+
yield "value"
1662+
finally:
1663+
cleanup_log.append("cleanup_attempted")
1664+
raise RuntimeError("async cleanup exploded")
1665+
1666+
async def healthy_gen():
1667+
try:
1668+
yield "healthy"
1669+
finally:
1670+
cleanup_log.append("healthy_cleanup")
1671+
1672+
def endpoint(a=Depends(failing_cleanup_gen), b=Depends(healthy_gen)):
1673+
return f"{a}_{b}"
1674+
1675+
result = await self.resolver.resolve_dependencies_async(
1676+
endpoint, self.request_data
1677+
)
1678+
assert result == {"a": "value", "b": "healthy"}
1679+
assert "cleanup_attempted" in cleanup_log
1680+
assert "healthy_cleanup" in cleanup_log
1681+
16291682
@pytest.mark.asyncio
16301683
async def test_mixed_async_and_sync_generators(self):
16311684
"""Test mixing async and sync generators in async context"""

0 commit comments

Comments
 (0)