You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
UNION in SQL causes TypeError: Argument 'val' has incorrect type (expected tuple, got list), in converters.pyx line 23, in asyncmy.converters.escape_item
#844
Closed
1 task done
mrmichaelrb opened this issue
Sep 8, 2022
· 2 comments
The following type of query works fine with normal sync SQLAlchemy engine/connection/execute, but throws a TypeError exception "Argument 'val' has incorrect type (expected tuple, got list)" when using mysql+aiomysql and async engine/connection/execute:
SELECT column1, column2
FROM table1
UNION
SELECT column1, column2
FROM table2
To Reproduce
Query a MySQL database using SQLAlchemy with two SELECT statements combined with a UNION operator.
Expected behavior
When using a UNION operator, an async query should return the same results as a sync query, instead of throwing an exception.
Logs/tracebacks
TypeError: Argument 'val' has incorrect type (expected tuple, got list)
Traceback (most recent call last):
...
File "\venv\lib\site-packages\asgiref\sync.py", line 218, in __call__return call_result.result()
File "C:\Program Files\Python\Python310\lib\concurrent\futures\_base.py", line 439, in resultreturnself.__get_result()
File "C:\Program Files\Python\Python310\lib\concurrent\futures\_base.py", line 391, in __get_resultraiseself._exception
File "\venv\lib\site-packages\asgiref\sync.py", line 284, in main_wrap
result =awaitself.awaitable(*args, **kwargs)
File "\tarvis\indicators\ma.py", line 42, in get_kline_history_table_smas_async
samples =await get_kline_history_table_close_samples_async(
File "\venv\lib\site-packages\dependency_injector\wiring.py", line 906, in _patchedreturnawait _async_inject(
File "src/dependency_injector/_cwiring.pyx", line 66, in _async_inject
File "\tarvis\indicators\sampling.py", line 109, in get_kline_history_table_close_samples_async
query_result =await db_connection.execute(
File "\venv\lib\site-packages\sqlalchemy\ext\asyncio\engine.py", line 451, in execute
result =await greenlet_spawn(
File "\venv\lib\site-packages\sqlalchemy\util\_concurrency_py3k.py", line 126, in greenlet_spawn
result = context.throw(*sys.exc_info())
File "\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1631, in _execute_20return meth(self, args_10style, kwargs_10style, execution_options)
File "\venv\lib\site-packages\sqlalchemy\sql\elements.py", line 332, in _execute_on_connectionreturn connection._execute_clauseelement(
File "\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1498, in _execute_clauseelement
ret =self._execute_context(
File "\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1862, in _execute_contextself._handle_dbapi_exception(
File "\venv\lib\site-packages\sqlalchemy\engine\base.py", line 2047, in _handle_dbapi_exception
util.raise_(exc_info[1], with_traceback=exc_info[2])
File "\venv\lib\site-packages\sqlalchemy\util\compat.py", line 208, in raise_raise exception
File "\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1819, in _execute_contextself.dialect.do_execute(
File "\venv\lib\site-packages\sqlalchemy\engine\default.py", line 732, in do_execute
cursor.execute(statement, parameters)
File "\venv\lib\site-packages\sqlalchemy\dialects\mysql\asyncmy.py", line 92, in executereturnself.await_(self._execute_async(operation, parameters))
File "\venv\lib\site-packages\sqlalchemy\util\_concurrency_py3k.py", line 68, in await_onlyreturn current.driver.switch(awaitable)
File "\venv\lib\site-packages\sqlalchemy\util\_concurrency_py3k.py", line 121, in greenlet_spawn
value =await result
File "\venv\lib\site-packages\sqlalchemy\dialects\mysql\asyncmy.py", line 104, in _execute_async
result =awaitself._cursor.execute(operation, parameters)
File "asyncmy\cursors.pyx", line 178, in execute
File "asyncmy\cursors.pyx", line 156, in asyncmy.cursors.Cursor.mogrify
File "asyncmy\cursors.pyx", line 129, in genexpr
File "asyncmy\cursors.pyx", line 129, in genexpr
File "asyncmy\connection.pyx", line 426, in asyncmy.connection.Connection.literal
File "asyncmy\connection.pyx", line 419, in asyncmy.connection.Connection.escape
File "asyncmy\converters.pyx", line 10, in asyncmy.converters.escape_item
File "asyncmy\converters.pyx", line 23, in asyncmy.converters.escape_item
Python Version
Python 3.10.5
aiomysql Version
Name: aiomysqlVersion: 0.1.1
PyMySQL Version
Name: PyMySQLVersion: 1.0.2
SQLAlchemy Version
Name: SQLAlchemyVersion: 1.4.39
OS
Windows [Version 10.0.19044.1889]
Database type and version
MySQL8.0.29
Additional context
No response
Code of Conduct
I agree to follow the aio-libs Code of Conduct
The text was updated successfully, but these errors were encountered:
Describe the bug
The following type of query works fine with normal sync SQLAlchemy engine/connection/execute, but throws a TypeError exception "Argument 'val' has incorrect type (expected tuple, got list)" when using mysql+aiomysql and async engine/connection/execute:
SELECT column1, column2
FROM table1
UNION
SELECT column1, column2
FROM table2
To Reproduce
Query a MySQL database using SQLAlchemy with two SELECT statements combined with a UNION operator.
Expected behavior
When using a UNION operator, an async query should return the same results as a sync query, instead of throwing an exception.
Logs/tracebacks
Python Version
Python 3.10.5
aiomysql Version
PyMySQL Version
SQLAlchemy Version
OS
Windows [Version 10.0.19044.1889]
Database type and version
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: