Queries with more than 32767 arguments are refused, PostgreSQL accepts 65535
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 18/100
Piste de recherche
The limit lives in asyncpg/protocol/prepared_stmt.pyx (the check near lines 130-132 and the count handling near 348-353) and its declaration in prepared_stmt.pxd. Run the test named test_prepare_28_max_args to see the current 32767 ceiling. Pull request #1391 already carries this change, so review or build on that rather than starting a parallel fix. Done means the counts are unsigned, the limit is 65535, and the test passes.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
- asyncpg version: 0.32.0, same on master (13b0191)
- PostgreSQL version: 17
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: no, local Dockerpostgres:17 - Python version: 3.12
- Platform: macOS
- Do you use pgbouncer?: no
- Did you install asyncpg with pip?: yes, and built master locally for the check below
- If you built asyncpg locally, which version of Cython did you use?: 3.2.x
- Can the issue be reproduced under both asyncio and
uvloop?: tried asyncio only; the limit is in the protocol code
asyncpg refuses more than 32767 query arguments (prepared_stmt.pyx#L130-L132) and keeps the parameter count in int16_t (prepared_stmt.pxd#L24, prepared_stmt.pyx#L348-L353). The limit comes from #127, where the Int16 in the Bind message was read as signed.
PostgreSQL reads that count as unsigned: exec_bind_message takes it with pq_getmsgint(input_message, 2) (postgres.c#L1725), which returns a uint16 (pqformat.c#L419-L430), and the docs list 65,535 query parameters as the limit (PostgreSQL Limits, listed since 12). libpq allows the same (libpq-fe.h#L490), so psycopg runs the same statements with up to 65535 parameters.
As a result, a multi-row INSERT ... VALUES has to be split at half of what the server accepts.
import asyncio
import importlib.metadata as md
import asyncpg
import psycopg
DSN = "postgresql://postgres@localhost/postgres"
def query(n, mark):
return "SELECT count(*) FROM (VALUES {}) v(x)".format(
", ".join("({}::int)".format(mark(i)) for i in range(1, n + 1))
)
async def main():
print("asyncpg", md.version("asyncpg"), "psycopg", md.version("psycopg"))
conn = await asyncpg.connect(DSN)
for n in (32767, 32768, 65535):
try:
print(f"asyncpg {n}:", await conn.fetchval(query(n, lambda i: f"${i}"), *range(n)))
except asyncpg.InterfaceError as e:
print(f"asyncpg {n}: {e}")
with psycopg.connect(DSN) as pg:
print(f"psycopg {n}:", pg.execute(query(n, lambda i: "%s"), range(n), prepare=True).fetchone()[0])
await conn.close()
asyncio.run(main())
asyncpg 0.33.0.dev0+13b0191 psycopg 3.3.6
asyncpg 32767: 32767
psycopg 32767: 32767
asyncpg 32768: the number of query arguments cannot exceed 32767
psycopg 32768: 32768
asyncpg 65535: the number of query arguments cannot exceed 32767
psycopg 65535: 65535
Keeping the counts as uint16_t and raising the check to 65535 fixes it, and the bytes on the wire stay the same for up to 32767 arguments.
I have that ready with an updated test_prepare_28_max_args and will open a PR.
- Langage dominant
- Python
- Étoiles
- 8.1k
- Forks
- 477
- Merge moyen
- 1 j 7 h
- PR mergées (30 j)
- 23
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de MagicStack/asyncpg
-
Failed BEGIN leaves Connection._top_xact set; every later transaction becomes a SAVEPOINT and fails with NoActiveSQLTransactionErrorPeut-être pris @devtechedge l’a pris il y a 8 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 35/100
MagicStack/asyncpg#1386 ·
Les mainteneurs répondent en général sous 1 jour
-
Connect call failed error doesn't distinguish port mismatch from "server not running"Peut-être pris @aryansk l’a pris il y a 61 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 72/100
MagicStack/asyncpg#1342 ·
Les mainteneurs répondent en général sous 1 jour
-
TypeError in asyncpg.connect() for specific parameters when values are not str enoughPeut-être pris @pranjalm37 l’a pris il y a 64 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 56/100
MagicStack/asyncpg#1340 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
setup.py relies on deprecated pkg_resourcesPeut-être pris @jasonwbarnett l’a pris il y a 92 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 28/100
MagicStack/asyncpg#1337 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 42/100
MagicStack/asyncpg#1330 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de MagicStack/asyncpg
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
common-workflow-language/cwl-utils#477 ·
Les mainteneurs répondent en général sous 1 jour
-
Add dependabotOuvertefeat
Difficulté 2/5 Moins d'une heure Accessibilité débutants 72/100
open-nudge/opentemplate#204 ·
Les mainteneurs répondent en général sous 1 jour
-
github-stale-ci-pr-closer: KV state is double-wrapped, never persists, and hits the depth-32 limitPeut-être pris @VascoSch92 l’a pris aujourd’hui. Ouvertepriority:medium ready-for-dev
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
OpenHands/extensions#781 ·
Les mainteneurs répondent en général sous 1 jour
-
bug good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
curriculum documentation quality
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
githubnext/gh-aw-workshop#4638 ·
Les mainteneurs répondent en général sous 1 jour