Description
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
The docs show an example for how to set up different callbacks for different tables when setting up realtime postgres events with the Python client.
changes = supabase.channel('db-changes').on_postgres_changes(
"*",
schema="public",
table="messages"
callback=lambda payload: print(payload)
).on_postgres_changes(
"INSERT",
schema="public",
table="users",
callback=lambda payload: print(payload)
).subscribe()
But when changes come in, it actually triggers the callback for every handler that was registered on the channel. So in this example with two handlers, any update on the messages table would print the event two times.
Expected behavior
I expect each callback handler to only be executed once per event, independent of how many handlers are registered on different tables.
System information
- Version of supabase-py: 2.15.0
- Version of realtime-py: 2.4.2
Additional context
From a quick look at the source code I think that this might be the issue (file realtime/_async/channel.py
, line 520):
if type_lowercase in ["insert", "update", "delete"]:
postgres_changes = filter(
lambda binding: binding.filter.get("event", "").lower()
in [type_lowercase, "*"],
self.bindings.get("postgres_changes", []),
)
for binding in postgres_changes:
binding.callback(payload, ref)
If I understand this correctly, the table
filter of the postgres_changes
channel isn't actually used on the client side and therefore each binding that exists calls its own handler. Is that right?