You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Celery results are NOT obeying results serializer config in databases #3025
So, we're working on getting all of our tasks results stored in a database backend (for now just postgres, but we're not tied to any particular backend).
Anyway, we've noticed that no matter what we try to do, the results are always stored as a pickle object, even though we have the other configurations set properly:
While not being terribly familiar with SQL Alchemy, I do believe we have found the offending line.
Am I understanding this right? To me, it looks like this has been a bug for years... is it because we might be the only ones using a database backend? :-P
Thanks!
Reacted by earlgreyness, Jakub Juraszek, Dmitrii Prisacari, Greg Najda, Davis Kirkendall, Will Koehrsen, Max Limsukhawat, Moritz Schott and Tamer Salama
@czchen That's great to hear! MongoDB appears to work, so good luck! I spoke with someone on IRC about this last night, and it looks like they want to see a patch for v4.0 first, and then they'll think about backporting to 3.1.
They're obviously concerned about making any breaking changes, but in the meantime I think documentation should be amended to indicate the bug/inconsistency and this issue should be left open and unresolved.
On a side note, we may write a custom backend that will obey CELERY_RESULT_SERIALIZER. If I do, I'll contribute upstream.
Guys .. I lost a lot of time trying to figure it out what is wrong with results stored in database as I expected them to be JSON and there were actually storead as Pickle ... This bug/issue is hanging a long time and the least decent thing to do is to state in documentation that even when you configure as recommended:
The bug is that Task.result/TaskSet.result use sa.PickleType, which
pickles/unpickles at the ORM level regardless of result_serializer.
The fix i tried to implement is that columns become sa.LargeBinary (same DDL as PickleType under the
hood, no migration needed) and the backend now calls encode()/decode()
itself, same idea as #2881/#5907. Old rows are always pickle no matter the
configured serializer, so decoding falls back to pickle.loads() when the
configured serializer can't parse a row.
In #5907@auvipy's comment about a native JSON column — tried it, doesn't work:
inserting pickle bytes into a sa.JSON column raises "Object of type
bytes is not JSON serializable". Since result_serializer can also be
pickle/msgpack/yaml, LargeBinary is the only type that works for all of
them.
I added a couple of tests on the PR for testing backward-compat
Activity
czchen commentedon Jan 26, 2016
@fxfitz, you are not along. We plan to give MongoDB a try to see if it is is more suitable for our need.
fxfitz commentedon Jan 26, 2016
@czchen That's great to hear! MongoDB appears to work, so good luck! I spoke with someone on IRC about this last night, and it looks like they want to see a patch for v4.0 first, and then they'll think about backporting to 3.1.
They're obviously concerned about making any breaking changes, but in the meantime I think documentation should be amended to indicate the bug/inconsistency and this issue should be left open and unresolved.
On a side note, we may write a custom backend that will obey CELERY_RESULT_SERIALIZER. If I do, I'll contribute upstream.
auvipy commentedon Jan 19, 2018
what's the update on the issue? any pr? workaround?
jfach commentedon Mar 23, 2018
@fxfitz have you been able to solve this issue? Currently dealing with this myself using Sqlite.
@auvipy any internal information/updates you can give us?
fxfitz commentedon Mar 23, 2018
Sadly, I moved off of that project and am working on something else now. Sorry!
jfach commentedon Mar 23, 2018
@fxfitz Ok, thanks for the quick response
nick4u commentedon Mar 8, 2019
Guys .. I lost a lot of time trying to figure it out what is wrong with results stored in database as I expected them to be JSON and there were actually storead as Pickle ... This bug/issue is hanging a long time and the least decent thing to do is to state in documentation that even when you configure as recommended:
in-database results will be Pickle objects.
Best regards - great project.
thedrow commentedon Apr 4, 2019
I don't see the offending line anymore.
@nick4u Did you try this on a recent version of Celery?
Also, if you feel like adding a note about this, feel free to issue a PR.
adimux commentedon Apr 19, 2019
The offending line is still there: https://github.com/celery/celery/blob/master/celery/backends/database/models.py#L29
The result column is of type Pickle. It works because the pickle type simply stores anything you pass to it as a BLOB in the DB and restores it when reading from the field.
The question is: should the result be serialized using the result serializer and be stored in a text field?
24 remaining items
rodionterekhin commentedon Nov 1, 2024
Still no progress in 2024???
thedrow commentedon Nov 5, 2024
Contributions are welcome.
tamersalama commentedon Mar 11, 2025
Who's here in 2025?
WZhijun154 commentedon Jun 2, 2025
hope updates on this issue/bug
auvipy commentedon Jun 2, 2025
I will personally handle this. Very soon.
ghirailghiro commentedon Aug 30, 2026
Hi @auvipy opened #10536, building on the approach from #2881 and #5907.
The bug is that
Task.result/TaskSet.resultusesa.PickleType, whichpickles/unpickles at the ORM level regardless of
result_serializer.The fix i tried to implement is that columns become
sa.LargeBinary(same DDL as PickleType under thehood, no migration needed) and the backend now calls encode()/decode()
itself, same idea as #2881/#5907. Old rows are always pickle no matter the
configured serializer, so decoding falls back to pickle.loads() when the
configured serializer can't parse a row.
In #5907 @auvipy's comment about a native JSON column — tried it, doesn't work:
inserting pickle bytes into a
sa.JSONcolumn raises "Object of typebytes is not JSON serializable". Since result_serializer can also be
pickle/msgpack/yaml, LargeBinary is the only type that works for all of
them.
I added a couple of tests on the PR for testing backward-compat
Fix: DatabaseBackend now honors result_serializer (#3025) (#10536)