Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: no encoder for OID 1000 #122

Closed
songololo opened this issue Apr 12, 2017 · 4 comments
Closed

RuntimeError: no encoder for OID 1000 #122

songololo opened this issue Apr 12, 2017 · 4 comments
Assignees
Labels

Comments

@songololo
Copy link

songololo commented Apr 12, 2017

After inserting around 25,000 items into a database, I'll start getting this error:

RuntimeError: no encoder for OID 1000

which I've isolated to a boolean array data type (boolean[7][24]). (The error doesn't occur when I don't set this value).

It is a nested list of 7*24 elements, which is converted from a numpy array to a python list via the numpy to_list() method.

The asyncpg version is 0.10.1

@elprans
Copy link
Member

elprans commented Apr 12, 2017

Do you mind sharing the actual query and the table structure on which this can be reproduced?

This works for me:

        res = await self.con.fetchval('''
            SELECT $1::bool[][]
        ''', [[True, False], [False, True]])

@songololo
Copy link
Author

songololo commented Apr 13, 2017

@elprans

The issue occurs under different conditions than I originally thought. It is not caused by nested arrays, but under some scenarios where I'm working with both array and geom types. I've pasted-in an example scenario below that triggers the issue on my system:

  • The error only occurs if inserting both the array and the geometry type
  • If using a pool, then the error occurs at 25,000 items
  • When directly using the connection (no pool), then the error occurs right away.

This will replicate the issue for me (requires PostGIS extension):

import asyncio
import asyncpg

async def array_vs_geom():

    db_connection = await asyncpg.connect(
        host='localhost',
        port=5432,
        user='my_username'
    )

    await db_connection.execute('''
        CREATE SCHEMA IF NOT EXISTS my_schema;
        CREATE TABLE IF NOT EXISTS my_schema.my_table (
            id text PRIMARY KEY,
            arr boolean[2],
            geom geometry(Point, 4326)
        );
        CREATE UNIQUE INDEX IF NOT EXISTS id_index_test ON my_schema.my_table (id);
    ''')

    for i in range(50000):
        if i % 1000 == 0:
            print(f'Processed {i}')
        try:
            await db_connection.execute(f'''
                INSERT INTO my_schema.my_table (id, arr, geom)
                  VALUES ($1, $2, ST_SetSRID($3::geometry, 4326))
                ON CONFLICT (id) DO UPDATE SET
                    arr = $2,
                    geom = ST_SetSRID($3::geometry, 4326)
                WHERE my_schema.my_table.id = $1
                ''',
                i,
                # happens regardless of specific array contents or dimensions
                [True, True],
                # happens regardless of specific geometry
                '01010000000C71568BA2F15BC01B419A196CB04040')
        except Exception as e:
            # error encountered at 25,000 items for pool, or immediately if no pool
            print(f' exception {e} at count {i}')
            raise e

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(array_vs_geom())

@songololo songololo changed the title nested array types - RuntimeError: no encoder for OID 1000 RuntimeError: no encoder for OID 1000 Apr 19, 2017
@elprans elprans added bug and removed need more info labels May 9, 2017
@elprans elprans self-assigned this May 9, 2017
@elprans
Copy link
Member

elprans commented May 9, 2017

Confirmed. I can reproduce this with your script.

elprans added a commit that referenced this issue May 9, 2017
set_builtin_type_codec() flushes the codec cache, so internal codec
aliasing (for enums and fallback) must use a version that doesn't
kill the cache.

Fixes: #133, #122.
1st1 pushed a commit that referenced this issue May 9, 2017
set_builtin_type_codec() flushes the codec cache, so internal codec
aliasing (for enums and fallback) must use a version that doesn't
kill the cache.

Fixes: #133, #122.
@elprans
Copy link
Member

elprans commented May 10, 2017

Fixed in df64f55.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants