Skip to content

Commit 34d042d

Browse files
committed
BUG#20065830: NaN is not supported
This patch adds support for NaN in the float to MySQL conversion. Tests were added for regression. Thanks for your contribution.
1 parent 30755b3 commit 34d042d

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ v8.0.29
1818
- WL#14665: SSPI Kerberos authentication for Windows (pure-python)
1919
- BUG#33729842: Character set 'utf8mb3' support
2020
- BUG#23338623: Add support for Decimal parsing in protocol.py
21+
- BUG#20065830: NaN is not supported
2122

2223
v8.0.28
2324
=======

lib/mysql/connector/conversion.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2009, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2009, 2022, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -30,6 +30,7 @@
3030
"""
3131

3232
import datetime
33+
import math
3334
import struct
3435
import time
3536
from decimal import Decimal
@@ -228,6 +229,8 @@ def _long_to_mysql(self, value):
228229

229230
def _float_to_mysql(self, value):
230231
"""Convert value to float"""
232+
if math.isnan(value):
233+
return None
231234
return float(value)
232235

233236
def _str_to_mysql(self, value):

tests/test_conversion.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
# Copyright (c) 2009, 2021, Oracle and/or its affiliates.
3+
# Copyright (c) 2009, 2022, Oracle and/or its affiliates.
44
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License, version 2.0, as
@@ -572,6 +572,7 @@ class MySQLConverterIntegrationTests(tests.MySQLConnectorTests):
572572
"my_bigint BIGINT, "
573573
"my_decimal DECIMAL(20,10), "
574574
"my_float FLOAT, "
575+
"my_float_nan FLOAT, "
575576
"my_double DOUBLE, "
576577
"my_date DATE, "
577578
"my_time TIME, "
@@ -596,6 +597,7 @@ class MySQLConverterIntegrationTests(tests.MySQLConnectorTests):
596597
"my_bigint, "
597598
"my_decimal, "
598599
"my_float, "
600+
"my_float_nan, "
599601
"my_double, "
600602
"my_date, "
601603
"my_time, "
@@ -606,7 +608,8 @@ class MySQLConverterIntegrationTests(tests.MySQLConnectorTests):
606608
"my_enum, "
607609
"my_geometry, "
608610
"my_blob) "
609-
"VALUES (%s, %s, B'1111100', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, "
611+
"VALUES (%s, %s, B'1111100', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, "
612+
"%s, %s, %s, %s, %s, %s, "
610613
"POINT(21.2, 34.2), %s)"
611614
)
612615

@@ -620,6 +623,7 @@ class MySQLConverterIntegrationTests(tests.MySQLConnectorTests):
620623
4294967295 if ARCH_64BIT else 2147483647,
621624
Decimal("1.2"),
622625
3.14,
626+
float("NaN"),
623627
4.28,
624628
datetime.date(2018, 12, 31),
625629
datetime.time(12, 13, 14),
@@ -642,6 +646,7 @@ class MySQLConverterIntegrationTests(tests.MySQLConnectorTests):
642646
4294967295 if ARCH_64BIT else 2147483647,
643647
Decimal("1.2000000000"),
644648
3.14,
649+
None,
645650
4.28,
646651
datetime.date(2018, 12, 31),
647652
datetime.timedelta(0, 43994),

0 commit comments

Comments
 (0)