MagicStack / MagicStack/asyncpg

set_type_codec() doesn't work with copy_records_to_table()

Offen
#762 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
8.1k
Forks
469
Ø Merge
18 Min.
Gemergte PRs (30 T.)
4

Beschreibung

  • asyncpg version: 0.23.0
  • PostgreSQL version: 9.5.21
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : No and this is on a local PSQL install.
  • Python version: 3.6.13
  • Platform: Ubuntu 16.04.6 LTS
  • 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?
    : Not tried

The following:

    await conn.set_type_codec(
        "numeric",
        encoder=str,
        decoder=float,
        schema="pg_catalog",
    )

Doesn't work when used with copy_records_to_table()

 ...
 File "asyncpg/protocol/protocol.pyx", line 504, in copy_in
  File "asyncpg/protocol/protocol.pyx", line 437, in asyncpg.protocol.protocol.BaseProtocol.copy_in
asyncpg.exceptions._base.InternalClientError: no binary format encoder for type numeric (OID 1700)

This is despite solving issue https://github.com/MagicStack/asyncpg/issues/157 which added a binary format codec for numeric types - https://github.com/MagicStack/asyncpg/commit/0f8483517ebde66f3c7cc858fa6ad227c6e3fd64

Can we get the ability to provide a custom decoder without having to also provide an encoder then internally just fall back to the default encoder? I believe it should solve the issue. E.g.

    await conn.set_type_codec(
        "numeric",
        decoder=float,
        schema="pg_catalog",
    )

or

    await conn.set_type_codec(
        "numeric",
        encoder=None,
        decoder=float,
        schema="pg_catalog",
    )

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

Reproduziere den Fehler mit set_type_codec() und copy_records_to_table() anhand des numerischen Beispiels aus dem Issue. Beginne in asyncpg/protocol/protocol.pyx bei copy_in und BaseProtocol.copy_in und verfolge anschließend, wie der benutzerdefinierte Codec ausgewählt wird. Als abgeschlossen gilt die Aufgabe, wenn ein benutzerdefinierter Decoder verwendet werden kann, während copy_records_to_table() weiterhin einen Encoder für numeric erhält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
postgresql, python
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 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.