Skip to content

Decode decimal fields independently of the active context - #488

Open
JackyHsu-X wants to merge 2 commits into
celery:mainfrom
JackyHsu-X:fix/decimal-decoding-context
Open

JackyHsu-X wants to merge 2 commits into
celery:mainfrom
JackyHsu-X:fix/decimal-decoding-context

Conversation

@JackyHsu-X

@JackyHsu-X JackyHsu-X commented Oct 23, 2026 •

Copy link
Copy Markdown

AMQP decimal fields are decoded with division, so the active decimal context can round valid message headers or raise an arithmetic exception. For example, decoding coefficient 2147483647 with scale 2 at precision 3 returns Decimal('2.15E+7') instead of Decimal('21474836.47'); enabling the Inexact trap makes decoding fail.

Construct the Decimal directly from its sign, digits and negative wire scale. This avoids context-dependent arithmetic and keeps the wire value exact without changing the caller's flags or settings.

The regression test decodes a raw field table containing both a nested table and an array, followed by an integer field. It covers signed 32-bit boundaries, scales 0 and 255, zero, low precision, restricted exponent bounds and enabled/disabled Inexact traps, and checks the final byte offset and unchanged context flags. A changelog entry is included.

Validation on Windows / Python 3.13.15:

  • Before the fix: 8 regression failures, 2 passes.
  • After the fix: python -m pytest t/unit t/integration -q — 400 passed, 27 skipped (RabbitMQ-dependent tests).
  • Repository pre-commit hook and git diff --check passed.
  • Flake8 on the changed Python files reports two existing findings (E123 and E275), both also present in the base versions; no new findings.

No live RabbitMQ or full Python-version matrix was run. This addresses decoding only; #487 addresses positive exponents on the encoding side.

Developed with assistance from OpenAI Codex.

Upstream integration (2026-11-02)

Updated the branch for main 9d4a51a (5.4.2). The only conflict was in Changelog: the pending Decimal fix remains in Unreleased, above the complete upstream 5.4.2 release notes. Upstream version changes are retained; the decoder and regression-test blobs are unchanged. Relative to updated main, the contribution remains three files, 39 insertions / 2 deletions.

The merged checkout passes all unit and simulated-protocol integration tests: 400 passed, 27 broker-dependent skips. Latest upstream still fails 8 of the 10 Decimal-context regression cases; the two zero-value controls pass. The configured trailing-whitespace hook was run directly from its existing v6.0.0 cached environment and passed, along with git diff --check. No dependency was installed or upgraded. Real RabbitMQ, other operating systems and the full Python matrix were not run. Codex prepared and validated this integration.

Signed-off-by: JackyHsu-X <xv1070733106@gmail.com>
@auvipy
auvipy self-requested a review October 24, 2026 03:29
@auvipy

auvipy commented Oct 24, 2026

Copy link
Copy Markdown
Member

@LuisFigueroaG can you review this?

@auvipy auvipy added this to the 5.5.x milestone Nov 2, 2026
Signed-off-by: JackyHsu-X <xv1070733106@gmail.com>
@JackyHsu-X

Copy link
Copy Markdown
Author

Updated the branch for main 9d4a51a (5.4.2). The only conflict was in Changelog: the pending Decimal fix remains in Unreleased, above the complete upstream 5.4.2 release notes. Upstream version changes are retained; the decoder and regression-test blobs are unchanged. Relative to updated main, the contribution remains three files, 39 insertions / 2 deletions.

The merged checkout passes all unit and simulated-protocol integration tests: 400 passed, 27 broker-dependent skips. Latest upstream still fails 8 of the 10 Decimal-context regression cases; the two zero-value controls pass. The configured trailing-whitespace hook was run directly from its existing v6.0.0 cached environment and passed, along with git diff --check. No dependency was installed or upgraded. Real RabbitMQ, other operating systems and the full Python matrix were not run. Codex prepared and validated this integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants