Skip to content

Conversation

@vadikko2
Copy link
Owner

@vadikko2 vadikko2 commented Jan 31, 2026

Summary by CodeRabbit

Release v4.7.3

  • New Features

    • Added tests verifying async-iterator consumption for mediators and handlers.
  • Refactor

    • Changed several streaming/dispatch/mediator entry points to return AsyncIterator shims delegating to new async implementations.
  • Chores

    • Bumped version to 4.7.3.
    • Removed inline type-check suppression comments.
    • Unified logging string formatting across handlers.

✏️ Tip: You can customize this high-level summary in your review settings.

Вадим Козыревский and others added 14 commits January 31, 2026 01:02
Docstrings generation was requested by @vadikko2.

* #52 (comment)

The following files were modified:

* `benchmarks/dataclasses/test_benchmark_cor_request_handler.py`
* `benchmarks/dataclasses/test_benchmark_event_handling.py`
* `benchmarks/dataclasses/test_benchmark_request_handling.py`
* `benchmarks/dataclasses/test_benchmark_saga_fallback.py`
* `benchmarks/dataclasses/test_benchmark_saga_memory.py`
* `benchmarks/dataclasses/test_benchmark_saga_sqlalchemy.py`
* `benchmarks/dataclasses/test_benchmark_stream_request_handler.py`
* `benchmarks/pydantic/test_benchmark_cor_request_handler.py`
* `benchmarks/pydantic/test_benchmark_event_handling.py`
* `benchmarks/pydantic/test_benchmark_request_handling.py`
* `benchmarks/pydantic/test_benchmark_saga_fallback.py`
* `benchmarks/pydantic/test_benchmark_saga_memory.py`
* `benchmarks/pydantic/test_benchmark_saga_sqlalchemy.py`
* `benchmarks/pydantic/test_benchmark_serialization.py`
* `benchmarks/pydantic/test_benchmark_stream_request_handler.py`

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
# Conflicts:
#	tests/benchmarks/dataclasses/test_benchmark_stream_request_handler.py
#	tests/benchmarks/pydantic/test_benchmark_stream_request_handler.py
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 31, 2026

📝 Walkthrough

Walkthrough

The changes implement an architectural refactor converting async streaming methods to synchronous functions returning AsyncIterator objects across request handlers, dispatchers, and mediators. Type-ignore directives are removed as the new pattern eliminates type checking conflicts. Examples and tests are updated accordingly, and the version is bumped to 4.7.3.

Changes

Cohort / File(s) Summary
Async-to-Sync Streaming Pattern Refactor
src/cqrs/dispatcher/saga.py, src/cqrs/dispatcher/streaming.py, src/cqrs/mediator.py, src/cqrs/requests/request_handler.py
Core architectural change converting async methods to synchronous methods returning AsyncIterator by delegating to new private _dispatch_impl or _stream_impl coroutines. Dispatch and stream methods no longer require await in caller code.
Type-Ignore Directive Cleanup
examples/fastapi_sse_streaming.py, examples/streaming_handler_parallel_events.py, tests/benchmarks/dataclasses/test_benchmark_stream_request_handler.py, tests/benchmarks/pydantic/test_benchmark_stream_request_handler.py, tests/integration/test_streaming_mediator.py, tests/unit/test_bootstrap_streaming_dependency_injector.py, tests/unit/test_streaming_dispatcher.py, tests/unit/test_streaming_mediator.py, tests/unit/test_streaming_outbox_background_processing.py
Removed inline type: ignore and # pyright: ignore[...] annotations from handle method definitions across test suites and examples, eliminating type-check suppression as the new architecture resolves override conflicts.
Logging and Annotation Formatting
examples/fastapi_sse_streaming.py, examples/streaming_handler_parallel_events.py
Consolidated multi-line logging string constructions into single-line expressions; reformatted type annotations (e.g., InventoryUpdateEvent.items) from multi-line to single-line format preserving semantic equivalence.
Bootstrap and Integration Updates
src/cqrs/saga/bootstrap.py, tests/integration/test_saga_mediator_memory.py, tests/unit/test_streaming_dispatcher.py, tests/unit/test_streaming_mediator.py
Updated attribute access from result.step_result.step_type to result.step_type; added new integration and unit tests verifying async iterator consumption via async for without awaiting the stream method.
Version Bump
pyproject.toml
Updated project version from 4.7.2 to 4.7.3.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Async no more, a sync refrain,
Iterator patterns, crystal and plain,
No awaits needed, just consume with grace,
Type-ignore gone, we cleaned up the place!
Streaming made simple, the coder's delight! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.98% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title contains a typo ('StramHandler' instead of 'StreamHandler') and is vague about the specific nature of the refactoring beyond the typo itself. Consider revising the title to 'Fix Saga and StreamHandler typing' or provide more specific detail about what typing issues were fixed (e.g., 'Refactor dispatch methods to return AsyncIterator without await').
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)

✅ Unit Test PR creation complete.

  • Create PR with unit tests
  • Commit unit tests in branch add-new-banchmarks
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.99%. Comparing base (1427c8c) to head (d99d288).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #55      +/-   ##
==========================================
+ Coverage   83.93%   83.99%   +0.05%     
==========================================
  Files          70       70              
  Lines        2428     2436       +8     
==========================================
+ Hits         2038     2046       +8     
  Misses        390      390              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link
Contributor

codspeed-hq bot commented Jan 31, 2026

Merging this PR will not alter performance

✅ 54 untouched benchmarks


Comparing add-new-banchmarks (d99d288) with master (1427c8c)

Open in CodSpeed

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@examples/streaming_handler_parallel_events.py`:
- Around line 444-452: The summary assertions and logs for results,
EMAIL_SENT_LOG, AUDIT_LOG, and ANALYTICS_STORAGE are running before the
fire-and-forget event handler tasks finish; move the await asyncio.sleep(0.3) so
it executes before the assertions/summary block that checks len(results),
len(EMAIL_SENT_LOG), len(AUDIT_LOG) and ANALYTICS_STORAGE["total_orders"]
against order_ids; this ensures the create_task-created handlers (EventProcessor
when concurrent_event_handle_enable=True) have time to complete before
verification.

In `@src/cqrs/saga/bootstrap.py`:
- Around line 188-190: The example iterates mediator.stream(order_context) and
incorrectly accesses result.step_type.__name__; update it to read the nested
property on SagaDispatchResult by using result.step_result.step_type.__name__
instead (SagaDispatchResult.step_result -> SagaStepResult.step_type) so the code
references the correct attribute path when printing step names.
🧹 Nitpick comments (3)
examples/fastapi_sse_streaming.py (3)

233-233: Consider using a single f-string.

The implicit concatenation of two f-strings works but is unnecessarily verbose. A single f-string would be cleaner.

✨ Suggested simplification
         logger.info(
-            f"Starting to process {len(request.file_ids)} files " f"with operation: {request.operation}",
+            f"Starting to process {len(request.file_ids)} files with operation: {request.operation}",
         )

310-310: Same pattern - consider a single f-string.

✨ Suggested simplification
         logger.info(
-            f"📄 File {event.file_id} processed: " f"{event.operation} ({event.file_size_mb} MB)",
+            f"📄 File {event.file_id} processed: {event.operation} ({event.file_size_mb} MB)",
         )

321-321: Same pattern - consider a single f-string.

✨ Suggested simplification
         logger.info(
-            f"📊 Analytics updated for file {event.file_id}: " f"{event.processing_time_ms}ms processing time",
+            f"📊 Analytics updated for file {event.file_id}: {event.processing_time_ms}ms processing time",
         )

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 31, 2026

Note

Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 31, 2026

✅ Created PR with unit tests: #56

@vadikko2 vadikko2 merged commit 245d268 into master Jan 31, 2026
11 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.

1 participant