Skip to content

postgresql: GetObjects schema filter depends on search_path #3854

@corleyma

Description

@corleyma

What happened?

When using the PostgreSQL ADBC driver via Python DBAPI, adbc_get_objects can fail to return tables in a non-default schema even when db_schema_filter is provided.

This appears to be caused by the driver’s table enumeration query using pg_catalog.pg_table_is_visible(c.oid), which is search_path-dependent. As a result, tables in a schema that is not currently on search_path may be omitted even if db_schema_filter specifies that schema.

How can we reproduce the bug?

  1. Create a schema and table in a non-default schema, leaving the current schema as public:
from adbc_driver_postgresql import dbapi

uri = "postgresql://postgres:password@localhost:5432/postgres"  # example

with dbapi.connect(uri) as conn:
    # default current schema is "public"
    with conn.cursor() as cur:
        cur.execute('CREATE SCHEMA IF NOT EXISTS "marimo_test"')
        cur.execute('DROP TABLE IF EXISTS "marimo_test"."t"')
        cur.execute('CREATE TABLE "marimo_test"."t" (ints INT)')
    conn.commit()

    reader = conn.adbc_get_objects(
        depth="tables",
        db_schema_filter="marimo_test",
        table_name_filter="t",
    )
    print(reader.read_all().to_pylist())

Expected behavior

The results should include schema marimo_test and table t.

Actual behavior

The table is omitted unless the schema is on search_path / the connection’s current schema is set accordingly.

Notes / suspected cause

The driver’s GetObjects tables query uses pg_catalog.pg_table_is_visible(c.oid) which filters based on search_path. This makes schema filtering behave unexpectedly when the requested schema is not on search_path.

Workaround

Set the connection’s current schema (or adjust search_path) to include the schema before calling adbc_get_objects.

Proposed fix

Remove pg_catalog.pg_table_is_visible(c.oid) from the table enumeration query and rely on the explicit schema predicate (n.nspname = $1) so db_schema_filter works as intended regardless of search_path.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions