CanopyTax/asyncpgsa

`pg.insert` lost all arguments

Closed this issue · 1 comments

pg.insert simply doesn't work:

Traceback (most recent call last):
  File "test.py", line 19, in <module>
    loop.run_until_complete(main())
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 466, in run_until_complete
    return future.result()
  File "test.py", line 6, in main
    val = await pg.insert('INSERT INTO users (nickname) VALUES ($1)', 'fantix')
  File "/Volumes/Home/fantix/py36env/lib/python3.6/site-packages/asyncpgsa/pgsingleton.py", line 91, in insert
    timeout=timeout)
  File "/Volumes/Home/fantix/py36env/lib/python3.6/site-packages/asyncpgsa/connection.py", line 138, in insert
    return await self.fetchval(query, *params, *args, **kwargs)
  File "/Volumes/Home/fantix/py36env/lib/python3.6/site-packages/asyncpgsa/connection.py", line 123, in fetchval
    return await super().fetchval(query, *args, **kwargs)
  File "/Volumes/Home/fantix/py36env/lib/python3.6/site-packages/asyncpg/connection.py", line 358, in fetchval
    data = await self._execute(query, args, 1, timeout)
  File "/Volumes/Home/fantix/py36env/lib/python3.6/site-packages/asyncpg/connection.py", line 1188, in _execute
    return await self._do_execute(query, executor, timeout)
  File "/Volumes/Home/fantix/py36env/lib/python3.6/site-packages/asyncpg/connection.py", line 1209, in _do_execute
    result = await executor(stmt, None)
  File "asyncpg/protocol/protocol.pyx", line 181, in bind_execute (asyncpg/protocol/protocol.c:66715)
  File "asyncpg/protocol/prepared_stmt.pyx", line 103, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg (asyncpg/protocol/protocol.c:62407)
ValueError: number of arguments (0) does not match number of parameters (1)

Looks like the overriden _execute method simply ignored the given args but only make use of the args found in the query object - if query is one:

    def _execute(self, query, args, limit, timeout, return_status=False):
        query, args = compile_query(query, dialect=self._dialect)
        return super()._execute(query, args, limit, timeout,
                                return_status=return_status)

The same happens with insert when using a SQLAlchemy core insert statement object with values included. Because the compile is done in insert, before _execute.

The fix is in 0.14.1