fix: TaskiqAdminMiddleware doesn't work with dataclasses#554
Merged
Conversation
0cf4e30 to
f3f57d7
Compare
f3f57d7 to
8a21f11
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where TaskiqAdminMiddleware was failing when task arguments contained dataclasses or other non-pydantic types. The fix converts TaskiqMessage and TaskiqResult objects to dictionaries using model_dump() before extracting fields for JSON serialization, ensuring proper serialization of nested objects.
Key changes:
- Modified
TaskiqAdminMiddlewareto usemodel_dump()on message and result objects before accessing their fields - Updated
taskiq/compat.pyto modernize type hints and fix a condition ordering issue - Replaced the old admin middleware test file with a new comprehensive test suite that verifies serialization of dataclasses, TypedDicts, and Pydantic models
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| taskiq/middlewares/taskiq_admin_middleware.py | Fixed serialization by converting messages/results to dicts before field access |
| taskiq/compat.py | Modernized type hints and fixed version comparison condition |
| tests/middlewares/test_taskiq_admin_middleware.py | Removed old test file |
| tests/middlewares/admin_middleware/test_arguments_formatting.py | Added new parameterized tests for different DTO types |
| tests/middlewares/admin_middleware/dto.py | Added test DTOs (dataclass, TypedDict, Pydantic) |
| tests/middlewares/admin_middleware/conftest.py | Added test fixtures for mock admin server and broker setup |
| pyproject.toml | Added polyfactory dependency for test data generation |
| uv.lock | Updated lock file with new dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
8a21f11 to
253624d
Compare
ae3180a to
9e0c8e8
Compare
9e0c8e8 to
8c053fe
Compare
s3rius
approved these changes
Nov 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.