Skip to content

postgrest: array filters (cs/cd/contains/contained_by/ov) raise TypeError on non-string values #1529

Description

@gottostartsomewhere

Bug

The array/range filter methods in the PostgREST query builder crash with TypeError when given a non-string iterable (e.g. an integer array), even though their signatures accept Iterable[Any]. Integer array columns (int[]) are common in Postgres, so .contains("ids", [1, 2, 3]) is a natural call.

in_ already handles this (it maps values through sanitize_param), but cs, cd, contains, contained_by, ov (and overlaps, which delegates to ov) do a bare ",".join(values) and fail.

Reproduce

from httpx import Client
from yarl import URL
from postgrest import SyncFilterRequestBuilder
from postgrest._sync.request_builder import RequestConfig

b = SyncFilterRequestBuilder(RequestConfig(Client(), URL('/t'), 'GET', {}, {}, None, {}))
b.contains('x', [1, 2, 3])   # TypeError: sequence item 0: expected str instance, int found

in_('x', [1, 2, 3]) works; cs/cd/contains/contained_by/ov/overlaps all raise.

Expected

The values should be coerced to str (as in_ effectively does), producing e.g. x=cs.{1,2,3}.

I have a fix + tests ready and will open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    PostgRESTIssues related to postgrest-pybugSomething isn't workingpythonPull requests that update Python code

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions