MagicStack / MagicStack/asyncpg

Unimplemented feature for INSERT queries on ARRAY columns with CockroachDB

Offen
#568 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
8.1k
Forks
468
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

* **asyncpg version**: 0.20.1
* **CockroachDB version**: 19.2.6
* **Python version**: 3.7.4
* **Platform**: MacOS Mojave 10.14.6
* **Do you use pgbouncer?**: No
* **Did you install asyncpg with pip?**: No, with `poetry`
* **Can the issue be reproduced under both asyncio and
[uvloop](https://github.com/magicstack/uvloop)?**: Yes

I'm using `Gino` as a PostgreSQL driver for `CockroachDB`. It doesn't work well for `INSERT` queries with `ARRAY` columns. There seems to be an introspection query executed by asyncpg when it didn't get enough knowledge about the types in the query:

https://github.com/MagicStack/asyncpg/blob/v0.20.1/asyncpg/introspection.py#L99-L134
https://github.com/MagicStack/asyncpg/blob/v0.20.1/asyncpg/connection.py#L328-L338

```
INFO: INSERT INTO image (id, s3_bucket, s3_key, formats, sizes, created_at) VALUES ($1, $2, $3, $4, $5, $6) RETURNING image.id, image.s3_bucket, image.s3_key, image.formats, image.sizes, image.created_at
INFO: ('2941f3a0-e2ea-4d9d-8e23-2ce7b793bcac', 'testbucket', 'iqEb1mDimiUpRsmG', ['jpeg'], [], 1588471074)
INFO: COMMIT
ERROR: Exception in ASGI application
Traceback (most recent call last):
...
created_obj = await cls(**kwargs).create()
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/gino/crud.py", line 485, in _create
row = await bind.first(q)
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/gino/engine.py", line 748, in first
return await conn.first(clause, *multiparams, **params)
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/gino/engine.py", line 328, in first
return await result.execute(one=True)
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/gino/dialects/base.py", line 215, in execute
context.statement, context.timeout, args, 1 if one else 0
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/gino/dialects/asyncpg.py", line 184, in async_execute
result, stmt = await getattr(conn, "_do_execute")(query, executor, timeout)
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/asyncpg/connection.py", line 1423, in _do_execute
stmt = await self._get_statement(query, None)
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/asyncpg/connection.py", line 338, in _get_statement
types_with_missing_codecs, timeout)
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/asyncpg/connection.py", line 378, in _introspect_types
self._intro_query, (list(typeoids),), 0, timeout)
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/asyncpg/connection.py", line 1411, in __execute
return await self._do_execute(query, executor, timeout)
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/asyncpg/connection.py", line 1423, in _do_execute
stmt = await self._get_statement(query, None)
File "/Users/son/Library/Caches/pypoetry/virtualenvs/project-rain-7LNSaARJ-py3.7/lib/python3.7/site-packages/asyncpg/connection.py", line 328, in _get_statement
statement = await self._protocol.prepare(stmt_name, query, timeout)
File "asyncpg/protocol/protocol.pyx", line 163, in prepare
asyncpg.exceptions.FeatureNotSupportedError: at or near "select": syntax error: unimplemented: this syntax
DETAIL: source SQL:
WITH RECURSIVE typeinfo_tree(
oid, ns, name, kind, basetype, has_bin_io, elemtype, elemdelim,
range_subtype, elem_has_bin_io, attrtypoids, attrnames, depth)
AS (
SELECT
ti.oid, ti.ns, ti.name, ti.kind, ti.basetype, ti.has_bin_io,
ti.elemtype, ti.elemdelim, ti.range_subtype, ti.elem_has_bin_io,
ti.attrtypoids, ti.attrnames, 0
FROM
(
SELECT
t.oid AS oid,
ns.nspname AS ns,
t.typname AS name,
t.typtype AS kind,
(CASE WHEN t.typtype = 'd' THEN
(WITH RECURSIVE typebases(oid, depth) AS (
SELECT
t2.typbasetype AS oid,
0 AS depth
FROM
pg_type t2
WHERE
t2.oid = t.oid

UNION ALL

SELECT
t2.typbasetype AS oid,
tb.depth + 1 AS depth
FROM
pg_type t2,
typebases tb
WHERE
tb.oid = t2.oid
AND t2.typbasetype != 0
) SELECT oid FROM typebases ORDER BY depth DESC LIMIT 1)
^
HINT: You have attempted to use a feature that is not yet implemented.
See: https://github.com/cockroachdb/cockroach/issues/21085
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Introspektionsabfrage in asyncpg/introspection.py um die Zeilen 99–134 und der Anweisungsverarbeitung in asyncpg/connection.py um die Zeilen 328–338. Reproduziere den INSERT mit ARRAY-Spalten gegen CockroachDB und verfolge die fehlschlagende rekursive Typabfrage; erledigt ist die Aufgabe, wenn kompatibles Verhalten hergestellt oder die Einschränkung mit Regressionsabdeckung dokumentiert wurde.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
postgresql, python
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.