Skip to content

Domain basetypes aren't loaded as encoders/decoders to the client cache #886

Closed
@QuantumTM

Description

@QuantumTM
  • asyncpg version: 0.22.0 (also tested on 0.25.0)
  • PostgreSQL version: 11
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : N/A
  • Python version: 3.8
  • 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?
    : Not tested

When attempting an insert on a domain type I hit an issue where asyncpg was unable to handle the numeric[] type;

Traceback (most recent call last):
  File "test.py", line 40, in <module>
    asyncio.run(main())
  File "/usr/local/lib/python3.8/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "test.py", line 36, in main
    await insert_num_array(conn, [1, 2])
  File "test.py", line 29, in insert_num_array
    await conn.execute(sql, (num_array,))
  File "/home/quantumtm/src/asyncpg/asyncpg/connection.py", line 320, in execute
    _, status, _ = await self._execute(
  File "/home/quantumtm/src/asyncpg/asyncpg/connection.py", line 1659, in _execute
    result, _ = await self.__execute(
  File "/home/quantumtm/src/asyncpg/asyncpg/connection.py", line 1684, in __execute
    return await self._do_execute(
  File "/home/quantumtm/src/asyncpg/asyncpg/connection.py", line 1711, in _do_execute
    stmt = await self._get_statement(
  File "/home/quantumtm/src/asyncpg/asyncpg/connection.py", line 416, in _get_statement
    settings.register_data_types(types)
  File "asyncpg/protocol/settings.pyx", line 35, in asyncpg.protocol.protocol.ConnectionSettings.register_data_types
    cpdef inline register_data_types(self, types):
  File "asyncpg/protocol/settings.pyx", line 36, in asyncpg.protocol.protocol.ConnectionSettings.register_data_types
    self._data_codecs.add_types(types)
  File "asyncpg/protocol/codecs/base.pyx", line 556, in asyncpg.protocol.protocol.DataCodecConfig.add_types
    elem_codec = self.declare_fallback_codec(
  File "asyncpg/protocol/codecs/base.pyx", line 706, in asyncpg.protocol.protocol.DataCodecConfig.declare_fallback_codec
    raise exceptions.UnsupportedClientFeatureError(
asyncpg.exceptions._base.UnsupportedClientFeatureError: unhandled standard data type 'numeric[]' (OID 1231)

On analysis this error can occure for any, none str, array type.

A minimal replication case is given below

import asyncio
import asyncpg
from asyncpg.connection import Connection

async def connect():
    return await asyncpg.connect(user="quantumtm", password="quantumtm", database="test", host="127.0.0.1")

async def setup(conn: Connection):
    sql = """
    DROP TABLE IF EXISTS test;
    DROP DOMAIN IF EXISTS num_array;
    CREATE DOMAIN num_array numeric[];
    CREATE TABLE test (
        num num_array
    );
    """
    await conn.execute(sql)

async def insert_num_array(conn: Connection, num_array):
    sql = "INSERT INTO test (num) VALUES ($1)"
    await conn.execute(sql, (num_array,))

async def main():
    conn = await connect()
    await setup(conn)
    await insert_num_array(conn, [1, 2])

if __name__ == '__main__':
    asyncio.run(main())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions