Skip to content

Watching for postgres changes always times out #1319

@bringert

Description

@bringert

Describe the bug

When subscribing to database changes using supabase-py, I see no events, until after about 10 seconds when I get Channel subscription state: RealtimeSubscribeStates.TIMED_OUT.

To check that it's a python problem and not something else, I tried this js code which works fine:

import { createClient } from '@supabase/supabase-js'

const supabase = createClient(
  process.env.SUPABASE_URL,
  process.env.SUPABASE_SERVICE_ROLE_KEY
)

const channel = supabase
  .channel('schema-db-changes')
  .on(
    'postgres_changes',
    {
      event: '*',
      schema: 'public',
    },
    (payload) => console.log(payload)
  )
  .subscribe()

Reproduction

import asyncio
import supabase
import os


async def watch_db(url, key):
    client = await supabase.acreate_client(url, key)

    def handle_payload(payload):
        print(payload)

    def subscribe_callback(state, error):
        if error:
            print(f"Error subscribing to channel: {error}")
        else:
            print(f"Channel subscription state: {state}")

    channel = client.channel("schema-db-changes")
    channel.on_postgres_changes("*", schema="public", callback=handle_payload)
    await channel.subscribe(subscribe_callback)

    await asyncio.Event().wait()


if __name__ == "__main__":
    asyncio.run(
        watch_db(os.environ["SUPABASE_URL"], os.environ["SUPABASE_SERVICE_ROLE_KEY"])
    )

Steps to reproduce

  1. Set env vars SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY to point to a locally running Supabase instance, mine has supabase/realtime:v2.65.2
  2. Install supabase-py 2.24.0 (I also tried with 2.23.2 and got the same result)
  3. Run the python code
  4. Do some DB insertions

Expected: I first see a SUBCRIBED event and then I see the db events

Observed: I see no events, until after about 10 seconds when I get Channel subscription state: RealtimeSubscribeStates.TIMED_OUT

Library affected

supabase-py

Library version

supabase 2.24.0; supabase/realtime:v2.65.2

Python version

Python 3.13.9; Python 3.14.0 on MacOS Tahoe 26.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions