Skip to content

Reject non-finite decimal.Decimal query parameters (NaN, sNaN, ±Infinity)#1237

Merged
methane merged 2 commits into
mainfrom
copilot/fix-decimal-nan-support
May 15, 2026
Merged

Reject non-finite decimal.Decimal query parameters (NaN, sNaN, ±Infinity)#1237
methane merged 2 commits into
mainfrom
copilot/fix-decimal-nan-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

PyMySQL already rejects non-finite float parameters before sending SQL, but equivalent decimal.Decimal values were still serialized and sent. This change aligns Decimal behavior with existing float safeguards for unsupported non-finite numeric parameters.

  • Converter behavior

    • Updated pymysql.converters.Decimal2Literal to reject non-finite Decimal values via Decimal.is_finite().
    • Non-finite values now raise ProgrammingError with the same message pattern already used for float ("<value> can not be used with MySQL"), normalized to lowercase.
  • Targeted test coverage

    • Added converter-level tests in pymysql/tests/test_converters.py for:
      • Decimal("NaN")
      • Decimal("sNaN")
      • Decimal("Infinity")
      • Decimal("-Infinity")
    • Each case asserts ProgrammingError is raised during literal conversion.
  • Example

    from decimal import Decimal
    from pymysql import converters
    
    converters.Decimal2Literal(Decimal("NaN"), None)
    # raises ProgrammingError: nan can not be used with MySQL

Copilot AI changed the title [WIP] Fix decimal.Decimal handling for NaN and Infinity Reject non-finite decimal.Decimal query parameters (NaN, sNaN, ±Infinity) May 15, 2026
Copilot AI requested a review from methane May 15, 2026 11:58
@methane methane marked this pull request as ready for review May 15, 2026 12:01
@methane methane merged commit c532b8d into main May 15, 2026
23 of 25 checks passed
@methane methane deleted the copilot/fix-decimal-nan-support branch May 15, 2026 12:06
methane pushed a commit that referenced this pull request May 15, 2026
- update `CHANGELOG.md` for `v1.2.0` release preparation
- add `Release date: TBD`
- add changelog entries for user-visible changes since `v1.1.3` (#1234,
#1235, #1236, #1237)
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.

Check decimal.Decimal("NaN"|"sNaN"|"Infinity"|"-Infinity") parameter.

2 participants