Skip to content

postgrest: range filters are typed as Tuple[int, int], so timestamp and numeric ranges fail type checking #1787

Open

Description

@Blacksujit

Describe the bug

range_gt, range_gte, range_lt, range_lte, range_adjacent (and sl, sr, nxl, nxr, adj) annotate the bounds as Tuple[int, int]. Range filters are mostly used on tsrange, tstzrange, daterange and numrange columns. The Python reference and this repo's own tests (tests/_async/test_filter_request_builder.py::test_range_greater_than) pass a list of timestamp strings:

supabase.table("reservations").select("*").range_gt(
    "during", ["2000-01-02 08:00", "2000-01-02 09:00"]
).execute()

At runtime this works: the bounds are formatted with f"({range[0]},{range[1]})". But mypy and pyright reject it, and they also reject float bounds such as (1.5, 9.99).

Reproduction

from postgrest import SyncPostgrestClient

client = SyncPostgrestClient("http://localhost:3000")
q = client.from_("reservations").select("*").range_gt(
    "during", ["2000-01-02 08:00", "2000-01-02 09:00"]
)
print(q.request.params)
client.from_("reservations").select("*").range_lt("price", (1.5, 9.99))
$ python repro.py
select=%2A&during=sr.%282000-01-02+08%3A00%2C2000-01-02+09%3A00%29
$ mypy repro.py
repro.py:8: error: Argument 2 to "range_gt" of "BaseFilterRequestBuilder" has incompatible type "list[str]"; expected "tuple[int, int]"  [arg-type]
repro.py:11: error: Argument 2 to "range_lt" of "BaseFilterRequestBuilder" has incompatible type "tuple[float, float]"; expected "tuple[int, int]"  [arg-type]

Library affected

postgrest (supabase-py)

Library version

postgrest 2.33.0 (main @ a662a51)

Python version

3.12

Suggested fix

Type the bounds as Sequence[FilterValue]. That is the FilterValue alias #1534 introduced for in_/cs/cd/ov. Runtime behaviour is unchanged. I have a patch with typed tests ready.

Activity

  1. added
    bugSomething isn't working
    pythonPull requests that update Python code
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpythonPull requests that update Python code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions