Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: expected str, got int #816

Closed
pavelschon opened this issue Jul 14, 2022 · 1 comment
Closed

TypeError: expected str, got int #816

pavelschon opened this issue Jul 14, 2022 · 1 comment
Labels
bug Describes a bug in the system.

Comments

@pavelschon
Copy link

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):

  • GINO: 1.0.1
  • SQLAlchemy: 1.3.24
  • Asyncpg: 0.24
@pavelschon pavelschon added the bug Describes a bug in the system. label Jul 14, 2022
@pavelschon
Copy link
Author

Not using this lib anymore, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Describes a bug in the system.
Projects
None yet
Development

No branches or pull requests

1 participant