List[str] parameter treated as text instead of text[] in certain requests
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Esegui le due riproduzioni di try_it() con asyncpg 0.27.0 e PostgreSQL 15.1, confrontandole con i cast espliciti ::text[]. Traccia come i parametri List vengono inferiti e codificati per le query VALUES e unnest. Il lavoro è completo quando entrambi gli esempi trattano la lista come text[] senza richiedere cast SQL, con copertura di regressione per i casi segnalati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- asyncpg version: 0.27.0
- PostgreSQL version: 15.1
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: No - Python version: 3.8.10
- Platform: Ubuntu
- Do you use pgbouncer?: No
- Did you install asyncpg with pip?: Yes
- If you built asyncpg locally, which version of Cython did you use?:
- Can the issue be reproduced under both asyncio and
uvloop?: Yes
I'm working with a custom bulk operations API built on top of SQLAlchemy and asyncpg, and some scenarios the List parameters are not treated as postgres arrays.
Example 1:
import asyncio
import asyncpg
async def try_it(table: str, query: str, *params, **connargs):
conn = await asyncpg.connect(**connargs)
try:
await conn.execute(f'CREATE TABLE test_table({table});')
await conn.execute(query, *params)
finally:
await conn.execute('DROP TABLE test_table;')
await conn.close()
table = 'a text[], b text'
query = """
UPDATE test_table SET a = uvals.a
FROM (VALUES ($1, $2)) AS uvals (a, b)
WHERE test_table.b = uvals.b
"""
params = [ ['hello', 'world'], 'helloworld']
db_conn_params = {}
asyncio.get_event_loop().run_until_complete(try_it(table, query, *params, **db_conn_params))
Response:
asyncpg.exceptions.DatatypeMismatchError: column "a" is of type text[] but expression is of type text
Example 2:
# same imports and try_it() from above
table = 'a text, b int'
query = """
SELECT a, b
FROM test_table
UNION
SELECT
values as a,
5 as b
FROM unnest($1) as values
"""
params = [ ['hello', 'world'] ]
# execution as above
Response:
asyncpg.exceptions.AmbiguousFunctionError: function unnest(unknown) is not unique
Adding a $1 :: text[] solves the problem in each case, since it appears to be passing the list as text but there are scenarios where I don't have direct control of the SQL (it being auto-generated).
- Lingua principale
- Python
- Stelle
- 8.1k
- Fork
- 469
- Merge medio
- 2g 20h
- PR unite (30g)
- 9
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MagicStack/asyncpg
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
MagicStack/asyncpg#1357 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
MagicStack/asyncpg#1354 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
MagicStack/asyncpg#1342 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
MagicStack/asyncpg#1340 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 28/100
MagicStack/asyncpg#1337 ·
Tutte le issue di MagicStack/asyncpg
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
learningequality/ricecooker#747 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
run-llama/llama_index#23199 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
KhronosGroup/glTF-Blender-IO#2769 ·