long2ice / asyncmy

A fast asyncio MySQL/MariaDB driver with replication protocol support
https://github.com/long2ice/asyncmy
Apache License 2.0
230 stars 25 forks source link

cannot connect: no attribute '_auth_plugin_name' #86

Open t184256 opened 4 months ago

t184256 commented 4 months ago

Cannot use asyncmy to connect to a specific server, while aiomysql works.

$ /usr/bin/python3 -m asyncio
...
>>> import aiomysql
>>> c = await aiomysql.connect(...)  # works fine
>>> import asyncmy
>>> c = await asyncmy.connect(...)
Traceback (most recent call last):
  File "/usr/lib64/python3.12/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "<console>", line 1, in <module>
  File "asyncmy/connection.pyx", line 1343, in _connect
  File "asyncmy/connection.pyx", line 594, in connect
  File "asyncmy/connection.pyx", line 572, in asyncmy.connection.Connection.connect
  File "asyncmy/connection.pyx", line 787, in _request_authentication
AttributeError: 'Connection' object has no attribute '_auth_plugin_name'. Did you mean: '_auth_plugin_map'?

Code inspection suggests that _request_authentication uses _auth_plugin_name unconditionally: https://github.com/long2ice/asyncmy/blob/044a4b0dee6dde6c7b828e11fd5a92bca4b75c52/asyncmy/connection.pyx#L787

... while it's only set if a certain condition is met: https://github.com/long2ice/asyncmy/blob/044a4b0dee6dde6c7b828e11fd5a92bca4b75c52/asyncmy/connection.pyx#L1013

Should it have some default pre-set?

Version: python3-asyncmy-0.2.9-1.fc39.x86_64 Server reports itself as MariaDB, Server version: 5.1.73-log Source distribution.

long2ice commented 4 months ago

Thanks for report! Could you make a PR?

t184256 commented 4 months ago

I don't know what the default should be.

t184256 commented 4 months ago

Hm, I've checked aiomysql (https://github.com/aio-libs/aiomysql/blob/83aa96e12b1b3f2bd373f60a9c585b6e73f40f52/aiomysql/connection.py#L218) and it uses "" as a default. I've tried setting it to "" and it seems to solve it for me. I don't see how "" could be worse than an absence of the attribute, so I'll file a PR.