set_type_codec() doesn't work with copy_records_to_table()
- 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",
)
This is despite solving issue #157 which added a binary format codec for numeric types - 0f84835
This is expected behavior. When you override a codec with set_type_codec, you override both builtin formats.
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?
That should be doable.