ViderStar opened a new pull request, #75627:
URL: https://github.com/apache/airflow/pull/75627
The serde serializer for `decimal.Decimal` turns every non-integral value
into a `float`. A float keeps about 17 significant digits, so anything more
precise is silently rounded when it goes through XCom. This hits a common path:
SQL operators and hooks return `NUMERIC`/`DECIMAL` columns as `Decimal`, and
those rows are pushed to XCom as is.
```python
from decimal import Decimal
from airflow.sdk.bases.xcom import BaseXCom
rows = [(1, Decimal("1234567890.123456789012345678")), (2,
Decimal("0.30000000000000000001"))]
BaseXCom.deserialize_value(type("R", (), {"value":
BaseXCom.serialize_value(rows)})())
# before: [(1, Decimal('1234567890.1234567')), (2, Decimal('0.3'))]
# after: [(1, Decimal('1234567890.123456789012345678')), (2,
Decimal('0.30000000000000000001'))]
```
`Decimal("NaN")` and `Decimal("Infinity")` also became float
`NaN`/`Infinity`, which is not valid JSON.
The fix stores the decimal string for non-integral values. Integral values
are still stored as JSON integers. No version bump is needed: `deserialize`
already does `Decimal(str(data))`, so it reads both the new string payloads and
the float payloads already stored in the metadata DB, and older Task SDK
versions can read the new payloads too.
Tests: added round-trip tests that check the exact value (`as_tuple()`, so
scale is kept too), NaN/Infinity staying valid JSON, and deserialization of an
old float payload. The new tests fail on `main` and pass with the change.
`pytest task-sdk/tests/task_sdk/serde` passes locally, except the two
Kubernetes tests that need the cncf.kubernetes provider, which is not installed
in my env. `prek` passes on the changed files.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
---
* Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information. Note: commit author/co-author name and email in commits
become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
You can add this file in a follow-up commit after the PR is created so you
know the PR number.
--
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]