[HOTFIX] Fix problem with injection asyncio Futures in DependencyInjectorCQRSContainer #40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐛 Bug Fixes
Fixed:
AttributeError: '_asyncio.Future' object has no attribute 'handle'in DependencyInjectorCQRSContainerProblem:
When using
DependencyInjectorCQRSContainerwith async providers or providers that returnFutureobjects, the container'sresolve()method was not properly awaiting these awaitable objects. This causedFutureobjects to be returned directly instead of the resolved handler instances, leading to the error:Root Cause:
The code was using
inspect.iscoroutine()to check if a provider result needed to be awaited. However,iscoroutine()only returnsTruefor coroutine objects (results of callingasync deffunctions), not forFutureorTaskobjects. When dependency-injector providers returnedFutureobjects (which can happen with async providers or certain provider configurations), the check failed and theFuturewas returned directly.Solution:
Replaced
inspect.iscoroutine(result)withinspect.isawaitable(result)inDependencyInjectorCQRSContainer.resolve(). Theisawaitable()function correctly identifies all awaitable objects including:__await__methodImpact:
DependencyInjectorCQRSContainerbootstrap_streaming()and parallel event processingFiles Changed:
src/cqrs/container/dependency_injector.py: Updatedresolve()method to useinspect.isawaitable()Testing:
test_resolve_async_provider_returns_futureto validate async provider resolutionRelated Issues:
This fix resolves issues when using
StreamingRequestMediatorwithDependencyInjectorCQRSContainerin scenarios where:Futureobjectsconcurrent_event_handle_enable=True)📝 Notes
This is a patch release that fixes a critical bug affecting users of
DependencyInjectorCQRSContainerwith async providers. The fix is backward compatible and does not introduce any breaking changes.Upgrade Recommendation:
All users experiencing the
'_asyncio.Future' object has no attribute 'handle'error should upgrade to this version.