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

Fails with queries with more than 32768 arguments #127

Closed
Fuyukai opened this issue Apr 29, 2017 · 1 comment
Closed

Fails with queries with more than 32768 arguments #127

Fuyukai opened this issue Apr 29, 2017 · 1 comment

Comments

@Fuyukai
Copy link

Fuyukai commented Apr 29, 2017

  • asyncpg version: 0.10.1
  • PostgreSQL version: 9.6.1
  • Python version: 3.5.3
  • Platform: GNU/Linux
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes
  • If you built asyncpg locally, which version of Cython did you use?: N/A
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : Yes

When sending queries with more than 32768 arguments, the execute fails with this error:

  File "asyncpg\protocol\protocol.pyx", line 162, in bind_execute (asyncpg/protocol/protocol.c:57595)
  File "asyncpg\protocol\prepared_stmt.pyx", line 100, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg (asyncpg/protocol/protocol.c:53533)
ValueError: number of arguments (90000) does not match number of parameters (24464)

Note that 90000 % 32768 is 24464.

EDIT: This is actually caused by overflow on 32768, not 65536.

@Fuyukai Fuyukai changed the title Fails with queries with more than 65536 arguments Fails with queries with more than 32768 arguments Apr 29, 2017
@1st1
Copy link
Member

1st1 commented May 3, 2017

From the Postgres documentation of its binary protocol, here's a description of the Bind message:

Bind (F)
    ...
    Int16
        The number of parameter format codes that follow (denoted C below). 
        This can be zero to indicate that there are no parameters or that the 
        parameters all use the default format (text); or one, in which case the 
        specified format code is applied to all parameters; or it can equal the 
        actual number of parameters.
    ...

Int16 is a signed 16 bit integer, so 32768 is how many arguments Postgres can accept.

We do need to handle this case and raise a proper exception in asyncpg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants