[Bugfix] Add saga context dataclass wizard supporitng #45
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
Saga Context Serialization and Recovery
Fixed context not being saved to storage after saga completion
COMPLETED. This could lead to data loss if the context was modified during the last step execution.COMPLETEDinSagaTransaction.__aiter__().Improved field filtering in
SagaContext.from_dict()SagaContext.from_dict()to only include known dataclass fields before deserialization.Test Improvements
Fixed test expectation for context reconstruction failures
test_recover_saga_raises_on_context_reconstruction_failurewas expectingTypeErrorwhen required fields were missing, butdataclass_wizardactually raisesMissingFieldsexception.MissingFieldsfromdataclass_wizard.errors).Changes
cqrs.saga.saga.SagaTransactionCOMPLETEDto ensure context persistence.cqrs.saga.models.SagaContextfrom_dict()method to filter input data to only include known dataclass fields, improving robustness during deserialization.Technical Details
Context Serialization
SagaContext.to_dict()usesdataclass_wizard.asdict()which converts field names to camelCase (e.g.,order_id→orderId).SagaContext.from_dict()now filters input data to only include fields that exist in the dataclass definition before deserialization.Saga Completion Flow
The saga completion process now follows this sequence:
COMPLETEDin storageThis ensures that any context modifications made during the last step are properly persisted.
Testing
All existing tests pass, including:
test_recover_saga_raises_on_context_reconstruction_failure- now correctly expectsMissingFieldsexceptiontest_recover_saga_updates_context_during_recovery- validates context persistence after recoveryMigration Notes
No breaking changes. This is a bug fix release that improves data consistency and error handling.
If you're using
SagaContext.from_dict()with data containing unknown fields, those fields will now be automatically filtered out. This should not affect normal usage but may change behavior if you were relying on unknown fields being passed through.