File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,18 @@ def test_non_primitive_uses_str(self):
7878
7979 assert _quote_value (date (2024 , 1 , 15 )) == "'2024-01-15'"
8080
81+ def test_nan_raises (self ):
82+ with pytest .raises (ProgrammingError , match = "Cannot convert float" ):
83+ _quote_value (float ("nan" ))
84+
85+ def test_inf_raises (self ):
86+ with pytest .raises (ProgrammingError , match = "Cannot convert float" ):
87+ _quote_value (float ("inf" ))
88+
89+ def test_negative_inf_raises (self ):
90+ with pytest .raises (ProgrammingError , match = "Cannot convert float" ):
91+ _quote_value (float ("-inf" ))
92+
8193
8294# ---------------------------------------------------------------------------
8395# cursor.execute() end-to-end tests
Original file line number Diff line number Diff line change 1+ import math
12import queue
23import re
34from typing import Any , List , Tuple , Dict
@@ -21,6 +22,10 @@ def _quote_value(value: Any) -> str:
2122 if isinstance (value , bool ):
2223 return "TRUE" if value else "FALSE"
2324 if isinstance (value , (int , float )):
25+ if isinstance (value , float ) and (math .isnan (value ) or math .isinf (value )):
26+ raise ProgrammingError (
27+ f"Cannot convert float value { value !r} to SQL literal"
28+ )
2429 return str (value )
2530 if isinstance (value , bytes ):
2631 return "X'" + value .hex () + "'"
You can’t perform that action at this time.
0 commit comments