Skip to content

Conversation

@vadikko2
Copy link
Owner

🐛 Bug Fixes

Fixed: AttributeError: '_asyncio.Future' object has no attribute 'handle' in DependencyInjectorCQRSContainer

Problem:
When using DependencyInjectorCQRSContainer with async providers or providers that return Future objects, the container's resolve() method was not properly awaiting these awaitable objects. This caused Future objects to be returned directly instead of the resolved handler instances, leading to the error:

AttributeError: '_asyncio.Future' object has no attribute 'handle'

Root Cause:
The code was using inspect.iscoroutine() to check if a provider result needed to be awaited. However, iscoroutine() only returns True for coroutine objects (results of calling async def functions), not for Future or Task objects. When dependency-injector providers returned Future objects (which can happen with async providers or certain provider configurations), the check failed and the Future was returned directly.

Solution:
Replaced inspect.iscoroutine(result) with inspect.isawaitable(result) in DependencyInjectorCQRSContainer.resolve(). The isawaitable() function correctly identifies all awaitable objects including:

  • Coroutines
  • Futures
  • Tasks
  • Any object with __await__ method

Impact:

  • ✅ Fixes the error when using async providers with DependencyInjectorCQRSContainer
  • ✅ Properly handles all types of awaitable objects returned by providers
  • ✅ No breaking changes - fully backward compatible
  • ✅ Works correctly with bootstrap_streaming() and parallel event processing

Files Changed:

  • src/cqrs/container/dependency_injector.py: Updated resolve() method to use inspect.isawaitable()

Testing:

  • Added test case test_resolve_async_provider_returns_future to validate async provider resolution
  • All existing tests continue to pass

Related Issues:
This fix resolves issues when using StreamingRequestMediator with DependencyInjectorCQRSContainer in scenarios where:

  • Providers return Future objects
  • Async providers are used
  • Parallel event processing is enabled (concurrent_event_handle_enable=True)

📝 Notes

This is a patch release that fixes a critical bug affecting users of DependencyInjectorCQRSContainer with 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.

Repository owner locked and limited conversation to collaborators Jan 23, 2026
Repository owner unlocked this conversation Jan 23, 2026
@lukashuk-da
Copy link
Collaborator

Approve

1 similar comment
@DimaPlaz
Copy link
Collaborator

Approve

@vadikko2 vadikko2 merged commit d0a5aeb into master Jan 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants