2sumtech opened a new pull request, #72064:
URL: https://github.com/apache/airflow/pull/72064
A task that returns a `decimal.Decimal` hands the next task a different
number. The serde encoder converts the value to a float before storing it, so
any Decimal that needs more than 53 bits of mantissa is silently rounded on its
way through XCom. The same encoder handles deferred-task trigger kwargs, so a
`Decimal` passed to `defer()` is rounded too.
`str` keeps every significant digit, so the encoder now uses it for values
that have digits after the decimal point. Whole numbers keep their existing
integer encoding.
**Repro on main**
```python
from decimal import Decimal
from airflow.sdk.serde import deserialize, serialize
for value in (Decimal("3.14159265358979323846"),
Decimal("12345678901234567.89")):
encoded = serialize(value)
print(value, "->", encoded["__data__"], "->", deserialize(encoded))
# 3.14159265358979323846 -> 3.141592653589793 -> 3.141592653589793
# 12345678901234567.89 -> 1.2345678901234568e+16 -> 12345678901234568
```
With this change both values come back unchanged.
**Compatibility**
The serializer version deliberately stays at 1. `deserialize` has rebuilt
the value with `Decimal(str(data))` ever since the serializer was added in
#28067, so every released Airflow reads a string payload as happily as a float
one. Bumping the version would do the opposite of helping, because an older
reader raises on any version above its own. Existing XCom rows written as
floats keep deserializing exactly as they do today.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Fable 5)
Generated-by: Claude Code (Fable 5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]