rioyu123 opened a new pull request, #4020: URL: https://github.com/apache/avro/pull/4020
## What is the purpose of the change Fixes [AVRO-3834](https://issues.apache.org/jira/browse/AVRO-3834), reported by Steve Stagg. The Python decimal encoder uses the value's digits without adjusting for the schema's scale. For example, `Decimal("3.1")` with `scale: 2` is written as unscaled `31` and reads back as `0.31`. Both `bytes` and `fixed` decimals are affected. This change adjusts the unscaled integer by `10 ** (scale + exponent)` before encoding it. Integer arithmetic keeps the result independent of the caller's Decimal precision. Values with too many fractional digits are still rejected as before. This is limited to scale adjustment. It does not add writer-side precision validation or address the separate existing negative-zero encoding issue. ## Verifying this change This change added tests and can be verified as follows: - Added 22 cases checking both the encoded integer and a `DatumWriter`/`DatumReader` round trip, across bytes/fixed, positive/negative values, whole numbers, scientific notation, and scales 0, 2 and 4. The encoder runs under a low-precision Decimal context. These regressions fail on the original encoder. - Existing excessive-fraction rejection tests remain unchanged and pass. - On Linux with CPython 3.12: Python SDK suite completed with 611 tests, 2 skipped; whole-SDK `ruff format --check`, `ruff check`, and `mypy avro/` passed. ## Documentation - Does this pull request introduce a new feature? no - If yes, how is the feature documented? not applicable AI disclosure: implementation and tests were prepared with OpenAI Codex; Claude Opus 5.5 reviewed the patch and drafted this description, which Codex edited. Review so far is by AI agents, not a human reviewer. -- 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]
