PyMySQL / mysqlclient

MySQL database connector for Python (with Python 3 support)

Home Page:https://mysqlclient.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conversion of float 'inf' to string fails after 1.3.14

zbentley opened this issue · comments

Read this first

Describe the bug

If I run cursor.execute("SELECT '%s' FROM dual", (float('inf'),), on 1.3.13 and earlier, I get (('inf',),) back, as expected. On later versions, I get a ProgrammingError raised by this converter indicating that infinity is not allowed.

That change was introduced with good intentions, but I do not think it makes sense. It's reasonable to want to stringify inf/nan and store that representation in a string column. Using a custom converter should not be necessary.

To Reproduce

Code

con = MySQLdb.connect(...)
cur = con.cursor()
cur.execute("SELECT '%s' FROM dual", (float('inf'),)

Environment

MySQL Server

  • Server OS: MacOS 12, Ubuntu 20
  • Server Version: MySQL 5.7

MySQL Client

  • OS MacOS 12
  • Python Pyenv 3.7.13
  • Connector/C Homebrew MySQL @5.7, linked.

str(float('inf')) is enough.