Skip to content

Binary parameters fail with PyMySQL 1.2.3, 'str' object is not callable #1080

Description

@HardMax71

With PyMySQL 1.2.3 any query with a bytes parameter fails.

connection.py line 20 imports escape_bytes_prefixed and line 418 calls it. In 1.2.3 that name is not a function any more:

# pymysql/converters.py
# This silly alias is needed for aiomysql compatibility for now. It is scheduled for removal in 1.3.0.
escape_dict = escape_bytes_prefixed = "DO NOT IMPORT THIS!!!"

The alias was added in 1.2.3 to unbreak the import in aiomysql/__init__.py, see PyMySQL/PyMySQL#1274. The import works again, the call doesn't.

Repro:

import asyncio

import aiomysql


async def main():
    conn = await aiomysql.connect(
        host="127.0.0.1", port=3306, user="scott", password="tiger", db="test"
    )
    async with conn.cursor() as cur:
        await cur.execute("CREATE TABLE IF NOT EXISTS t (id INT, data BLOB)")
        await cur.execute("INSERT INTO t VALUES (%s, %s)", (1, b"binary"))
    conn.close()


asyncio.run(main())
  File "aiomysql/cursors.py", line 197, in _escape_args
    return tuple(conn.escape(arg) for arg in args)
  File "aiomysql/connection.py", line 418, in escape
    return escape_bytes_prefixed(obj)
TypeError: 'str' object is not callable

Passes with PyMySQL 1.1.3.

Environment: aiomysql 0.3.2, PyMySQL 1.2.3, MariaDB 13.0.2, Python 3.13.

One more thing: that alias is scheduled for removal in PyMySQL 1.3.0, and escape_dict in aiomysql/__init__.py goes with it. At that point aiomysql won't import at all.

Related: #1077. PR follows.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions