Jump to solution
Verify

The Fix

pip install celery==5.6.0

Based on closed celery/celery issue #8634 · PR/commit linked

Production note: This usually shows up under retries/timeouts. Treat it as a side-effect risk until you can verify behavior with a canary + real traffic.

Jump to Verify Open PR/Commit
@@ -10,6 +10,8 @@ __all__ = ('Task', 'TaskExtended', 'TaskSet') +DialectSpecificInteger = sa.Integer().with_variant(sa.BigInteger, 'mssql') +
repro.py
from celery.backends.database import models from sqlalchemy import BigInteger # Monkey Patch for MSSQL Compatibility in Celery's Result Backend # --------------------------------------------------------------- # This code addresses a compatibility issue when using Microsoft SQL Server (MSSQL) # as the backend for Celery's task results. In MSSQL, the 'id' field in the results # tables can exceed the maximum value for an Integer data type, leading to overflow errors. # To prevent this, the data type of the 'id' column in both the Task and TaskSet models # is changed from Integer to BigInteger. This alteration ensures that the 'id' field can # accommodate larger values, aligning with MSSQL's capacity for handling big integers. # This patch modifies the column type directly in the SQLAlchemy table definition # for Celery's backend models before any tables are created in the database. # It is a simple yet effective solution to avoid overflow issues in MSSQL # while using Celery's database backend for storing task results. models.Task.__table__.c.id.type = BigInteger() models.TaskSet.__table__.c.id.type = BigInteger()
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install celery==5.6.0\nWhen NOT to use: This fix should not be applied if using a database backend other than MSSQL.\n\n

Why This Fix Works in Production

  • Trigger: sqlalchemy.exc.DataError: (pyodbc.DataError) ('22003', '[22003] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting…
  • Mechanism: The arithmetic overflow occurs due to an integer ID field limitation in the MSSQL backend
  • Why the fix works: Fixes an arithmetic overflow issue with the MSSQL backend by using a dialect-specific integer type for the ID field. (first fixed release: 5.6.0).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • The arithmetic overflow occurs due to an integer ID field limitation in the MSSQL backend
  • Surfaces as: sqlalchemy.exc.DataError: (pyodbc.DataError) ('22003', '[22003] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type…

Proof / Evidence

  • GitHub issue: #8634
  • Fix PR: https://github.com/celery/celery/pull/9904
  • First fixed release: 5.6.0
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-09
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.37

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“good shares. we can learn and incorporate some of the good suggestion you are sharing here in SQLA model code base”
@auvipy · 2023-11-12 · source
“never got any report regarding MSSQL bugs to be honest. are you suggesting that we should adjust the SQLA data types in celery to make…”
@auvipy · 2023-11-12 · source
“@dxdc If I want to use the monkeypatch you suggested while waiting for the long-term fix, where does that code need to be added (in…”
@twacn · 2024-02-26 · source
“@twacn you add it in the same place just before you initialize celery, e.g.”
@dxdc · 2024-02-26 · source

Failure Signature (Search String)

  • sqlalchemy.exc.DataError: (pyodbc.DataError) ('22003', '[22003] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type

Error Message

Stack trace
error.txt
Error Message ------------- sqlalchemy.exc.DataError: (pyodbc.DataError) ('22003', '[22003] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type int. (8115) (SQLExecDirectW)') [SQL: INSERT INTO results_taskmeta (id, task_id, status, result, date_done, traceback, name, args, kwargs, worker, retries, queue) OUTPUT inserted.id VALUES (NEXT VALUE FOR task_id_sequence, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ('c8c7432b-255f-49c4-b546-c7954d935e40', 'PENDING', <pyodbc.NullParam object at 0x7fea2ec0e610>, datetime.datetime(2023, 11, 11, 22, 32, 27, 680391), None, None, <pyodbc.NullParam object at 0x7fea2ec0e610>, <pyodbc.NullParam object at 0x7fea2ec0e610>, None, None, None)]

Minimal Reproduction

repro.py
from celery.backends.database import models from sqlalchemy import BigInteger # Monkey Patch for MSSQL Compatibility in Celery's Result Backend # --------------------------------------------------------------- # This code addresses a compatibility issue when using Microsoft SQL Server (MSSQL) # as the backend for Celery's task results. In MSSQL, the 'id' field in the results # tables can exceed the maximum value for an Integer data type, leading to overflow errors. # To prevent this, the data type of the 'id' column in both the Task and TaskSet models # is changed from Integer to BigInteger. This alteration ensures that the 'id' field can # accommodate larger values, aligning with MSSQL's capacity for handling big integers. # This patch modifies the column type directly in the SQLAlchemy table definition # for Celery's backend models before any tables are created in the database. # It is a simple yet effective solution to avoid overflow issues in MSSQL # while using Celery's database backend for storing task results. models.Task.__table__.c.id.type = BigInteger() models.TaskSet.__table__.c.id.type = BigInteger()

What Broke

Users experience arithmetic overflow errors when tasks exceed the integer limit in MSSQL.

Why It Broke

The arithmetic overflow occurs due to an integer ID field limitation in the MSSQL backend

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install celery==5.6.0

When NOT to use: This fix should not be applied if using a database backend other than MSSQL.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/celery/celery/pull/9904

First fixed release: 5.6.0

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be applied if using a database backend other than MSSQL.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
  • Pin production dependencies and upgrade only with a reproducible test that hits the failing path.

Version Compatibility Table

VersionStatus
5.6.0 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.