Describe the bug
A TypeError when passed integer to literal()
To Reproduce
import os
import asyncio
from gino import Gino
from sqlalchemy import Integer
db = Gino()
async def main():
await db.set_bind('FILLME')
query = db.select([ db.literal(1, type_=Integer).label('test') ], bind=db)
print(await query.gino.all())
await db.pop_bind().close()
asyncio.get_event_loop().run_until_complete(main())
Expected result
Expect to get an equivalent of this:
database=> select 1::int as test;
test
------
1
(1 row)
Actual result
Traceback (most recent call last):
File "asyncpg/protocol/prepared_stmt.pyx", line 155, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
File "asyncpg/protocol/codecs/base.pyx", line 193, in asyncpg.protocol.protocol.Codec.encode
File "asyncpg/protocol/codecs/base.pyx", line 104, in asyncpg.protocol.protocol.Codec.encode_scalar
File "asyncpg/pgproto/./codecs/text.pyx", line 29, in asyncpg.pgproto.pgproto.text_encode
File "asyncpg/pgproto/./codecs/text.pyx", line 12, in asyncpg.pgproto.pgproto.as_pg_string_and_size
TypeError: expected str, got int
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test_gino.py", line 18, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "test_gino.py", line 13, in main
print(await query.gino.all())
File "lib/python3.9/site-packages/gino/api.py", line 127, in all
return await self._query.bind.all(self._query, *multiparams, **params)
File "lib/python3.9/site-packages/gino/api.py", line 472, in all
return await self.bind.all(clause, *multiparams, **params)
File "lib/python3.9/site-packages/gino/engine.py", line 740, in all
return await conn.all(clause, *multiparams, **params)
File "lib/python3.9/site-packages/gino/engine.py", line 316, in all
return await result.execute()
File "lib/python3.9/site-packages/gino/dialects/base.py", line 214, in execute
rows = await cursor.async_execute(
File "lib/python3.9/site-packages/gino/dialects/asyncpg.py", line 184, in async_execute
result, stmt = await getattr(conn, "_do_execute")(query, executor, timeout)
File "lib/python3.9/site-packages/asyncpg/connection.py", line 1711, in _do_execute
result = await executor(stmt, None)
File "asyncpg/protocol/protocol.pyx", line 183, in bind_execute
File "asyncpg/protocol/prepared_stmt.pyx", line 171, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
asyncpg.exceptions.DataError: invalid input for query argument $1: 1 (expected str, got int)
Environment (please complete the following information):
Describe the bug A TypeError when passed integer to
literal()
To Reproduce
Expected result Expect to get an equivalent of this:
Actual result
Environment (please complete the following information):