Fix: DatabaseBackend now honors result_serializer (#3025) (#10536)
* Fix: DatabaseBackend now honors result_serializer (#3025)
The SQLAlchemy result backend stored Task.result and TaskSet.result as
sa.PickleType, which pickles/unpickles values at the ORM level regardless
of the configured result_serializer. This meant results were always
persisted as pickle even when result_serializer was set to json, msgpack,
etc., silently ignoring the setting.
Switch both columns to sa.LargeBinary and have the backend call
self.encode()/self.decode() explicitly, the same pattern already used by
the mongodb and redis backends. The column's DDL is unchanged (PickleType
already stores as a binary column under the hood), so no schema migration
is needed.
Rows written before this fix are always a raw pickle blob no matter what
result_serializer was configured, so decoding falls back to pickle.loads
when the configured serializer can't parse a row. This keeps existing
databases readable after upgrading; only newly written results use the
configured serializer.
* Support real GroupResult round-trips under non-pickle serializers
_save_group/_restore_group now go through self.prepare_value()/
result_from_tuple(), the same pattern already used by
BaseKeyValueStoreBackend, so GroupResult.save()/.restore() keeps working
when result_serializer isn't pickle (a real GroupResult isn't directly
JSON-encodable, so it needs to be flattened to its tuple form on the way
in and reconstructed on the way out).
test_save__restore__delete_group now saves/restores an actual GroupResult
instead of a plain dict, since that's the shape every other backend
already assumes; a new test covers the same round-trip under json
specifically, both flagged in PR review.
---------
Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <auvipy@gmail.com> M
Michele Ghirardelli committed
66d9602690081801e086541705d1ec4e1eb86ef6
Parent: e362d69
Committed by GitHub <noreply@github.com>
on 9/1/2026, 8:42:07 AM