Why not Celery pydantic=True alone?¶
Celery 5.5+ supports @app.task(pydantic=True). That is useful, but it only covers half the story.
What pydantic=True does¶
On the worker, Celery:
Converts kwargs dicts into Pydantic models using your annotations
Dumps return models to dicts via
model_dump()for the result backend
What it does not do¶
On the producer (your API, CLI, or script calling .delay()):
You must still serialize models yourself
Passing
OrderCreate(...)directly raises ``TypeError: not JSON serializable`
On the client (calling .get()):
You receive a dict, not your return model
Official docs quote¶
From the Celery task documentation:
Argument validation only covers arguments/return values on the task side. You still have serialize arguments yourself when invoking a task with delay() or apply_async().
Community reports¶
celery#9442 - models not serializable on enqueue
dramatiq#660 - JSON encoder fails on models
arq#497 - request for native Pydantic support
What queuebridge adds¶
Stage |
Celery alone |
With queuebridge |
|---|---|---|
|
Fails or needs |
Works |
Worker receives |
Model (with pydantic=True) |
Model (with pydantic=True) |
|
|
|
queuebridge does not replace Celery’s worker validation. It complements it by fixing producer serialization and offering client-side typed results.