MagicStack / MagicStack/asyncpg

Nested custom types in Postgres break `asyncpg.Record` subclassing

Offen
#891 2 Kommentare 1 Reaktion 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**: v0.25.0

* **PostgreSQL version**: 14

* **Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?**: on-premise

* **Python version**: 3.10.1
* **Platform**: 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](https://github.com/magicstack/uvloop)?**: n/a

It would appear that nested types are not converted to a user specified `record_class`, and instead will always use `asyncpg.Record`.

For example:

```

CREATE TYPE my_custom_type AS (
id int,
filename text,
sql text
);

CREATE TABLE my_table (
files my_custom_type[] NOT NULL,
);

SELECT * FROM my_table
```

If you specify a custom `record_class`, then the record from `SELECT * FROM my_table` will be your subclass. However, the value inside `record['files']` will use the `asyncpg.Record` class, rather than the custom one specified.

## What should actually happen?

I think if a user specifies a `record_class`, then this class should always be used, even for nested custom types. It's quite unexpected behaviour for `asyncpg` to use the default class when a custom one has been specified.

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 damit, das Problem mit dem benutzerdefinierten PostgreSQL-Typ, der Array-Spalte, der SELECT-Abfrage und einer benutzerdefinierten record_class zu reproduzieren, wie im Bericht beschrieben. Verfolge, wie verschachtelte Werte benutzerdefinierter Typen dekodiert werden und wie record_class weitergegeben wird; fertig ist die Arbeit, wenn die Datensätze innerhalb von record['files'] die angegebene Unterklasse statt asyncpg.Record verwenden und eine Regressionstestabdeckung für diesen Fall vorhanden ist.

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
42/100

Neue Issues direkt in Ihr Postfach

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