Skip to content

Commit

Permalink
🎨 Raise exception instead of hiding it in finally (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
gortibaldik authored Jan 5, 2025
1 parent d82d9fb commit f9db578
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dependency_injector/providers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3222,8 +3222,8 @@ cdef class ThreadLocalSingleton(BaseSingleton):
return future_result

self._storage.instance = instance
finally:
return instance

return instance

def _async_init_instance(self, future_result, result):
try:
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/providers/singleton/test_thread_local_singleton_py3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from dependency_injector.containers import Container
from dependency_injector.providers import ThreadLocalSingleton


class FailingClass:
def __init__(self):
raise ValueError("FAILING CLASS")


class TestContainer(Container):
failing_class = ThreadLocalSingleton(FailingClass)


def test_on_failure_value_error_is_raised():
container = TestContainer()

with pytest.raises(ValueError, match="FAILING CLASS"):
container.failing_class()

0 comments on commit f9db578

Please sign in to comment.