You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Celery运行任务触发ValueError异常,请求排查问题根源

Celery任务运行时出现ValueError异常:Exception information must include the exception type

环境配置

  • Redis 7.0.12
  • Celery 5.3.1
  • Python 3.9
  • kombu 5.3.1

执行命令

celery -A proj worker --loglevel=debug --pool=solo

报错信息

raise ValueError("Exception information must include "
ValueError: Exception information must include the exception type

  warn(RuntimeWarning(

[2023-08-25 02:19:44,070: CRITICAL/MainProcess] Unrecoverable error: ValueError('Exception information must include the exception type')
Traceback (most recent call last):
  File ".../venv/lib/python3.10/site-packages/celery/backends/base.py", line 354, in exception_to_python
    exc_type = exc['exc_type']
KeyError: 'exc_type'

已尝试在任务中添加try/except语句,但问题未解决,需明确问题根源。


问题根源分析

这个错误的核心是Celery从Redis后端读取任务异常信息时,找不到exc_type字段——这是Celery序列化异常元数据的必填项。

具体触发场景包括:

  1. Redis中异常数据损坏:之前某任务抛出异常后,Redis写入异常元数据时失败(比如网络中断、Redis服务异常),导致存储的异常信息缺失关键字段,后续worker读取时触发报错。
  2. 序列化格式不兼容:如果修改过Celery的task_serializer或result_serializer配置,新旧序列化格式不匹配,读取旧的异常数据时会解析失败,丢失exc_type。
  3. 版本边缘兼容问题:Redis 7.x与Celery 5.3.x的组合可能存在边缘场景的兼容性问题,导致异常信息的存储结构不符合预期。
  4. 自定义逻辑干扰:项目中如果有自定义异常处理器、结果后端改造逻辑,可能无意中修改了异常信息的存储结构,导致exc_type字段丢失。

任务内的try/except无法解决该问题,因为错误并非发生在任务执行阶段,而是worker读取历史任务异常结果时触发的。

内容的提问来源于stack exchange,提问作者Ivan Dorohov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 11:52:07