Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streams not showing delete event #1032

Closed
maxfornacon opened this issue Sep 13, 2024 · 8 comments
Closed

Streams not showing delete event #1032

maxfornacon opened this issue Sep 13, 2024 · 8 comments
Labels
bug Something isn't working realtime This issue or pull request is related to realtime

Comments

@maxfornacon
Copy link

maxfornacon commented Sep 13, 2024

Describe the bug
Streams don't react to deleted records.

I use a stream like this:

                StreamBuilder(
                  stream: Supabase.instance.client
                      .schema('xxx')
                      .from('notifications')
                      .stream(primaryKey: ['id'])
                      .eq('employee_id', '9418ce33-6349-45aa-895e-78e4423155dc'),
                  builder: (context, snapshot) {
                    if (snapshot.hasData) {
                      return Text('StreamBuilder1: ${snapshot.data!.length}');
                    } else {
                      if (snapshot.error != null) {
                        print('ERRROR1: ${snapshot.error.toString()}');
                      }
                      return const Text('StreamBuilder1: No data');
                    }
                  }
                )

It works when I add rows to the table, then the snapshot.data!.length increments, but when I delete entries, it doesn't decrement.

I also listen to the channel like this at the same time:

 var channel = Supabase.instance.client
        .channel('notifications')
        .onPostgresChanges(
      event: PostgresChangeEvent.all,
      schema: 'xxx',
      table: 'notifications',
      callback: (payload) {
        print('Change received: ${payload.toString()}');
      },
    ).subscribe();

Here it receives the delete event.

To Reproduce
Steps to reproduce the behavior:

  1. length = 0
  2. I add a row to table --> length = 1
  3. I delete that row --> length = 1 still
  4. I add a new row --> length = 2

Expected behavior
Stream gets notified about the delete event.

Version (please complete the following information):
Testing on macOS:

Happens for me on supabase_flutter: 2.6.0 (hosted) and the version from branch fix/realtime

@maxfornacon maxfornacon added the bug Something isn't working label Sep 13, 2024
@dshukertjr dshukertjr added the realtime This issue or pull request is related to realtime label Sep 14, 2024
@dshukertjr
Copy link
Member

@maxfornacon
In your stream, you have an eq filter, but in your realtime subscription, you don't. Have you tried applying an eq filter on the realtime subscription as well?

@maxfornacon
Copy link
Author

@dshukertjr
When I apply the eq filter to the realtime subscription, it seems to not receive the changes as well.

@dshukertjr
Copy link
Member

Thanks for the confirmation. I can see that other users are having the same trouble.
supabase/realtime#1154

I will ask the realtime team to look into this one.

@dshukertjr
Copy link
Member

dshukertjr commented Sep 14, 2024

@maxfornacon
Actually, could you verify that you have set the replica identity to full? I was able to get it to work with it.
https://supabase.com/docs/guides/realtime/postgres-changes#receiving-old-records

@maxfornacon
Copy link
Author

Screenshot 2024-09-14 at 15 47 24

You mean this? I have everything activated. And I didn't change anything recently when I remember correctly.

@dshukertjr
Copy link
Member

@maxfornacon No, it's not that one. Sorry, I thought I pasted the link to the relevant sections, but you need to run this SQL statement.
https://supabase.com/docs/guides/realtime/postgres-changes#receiving-old-records

@maxfornacon
Copy link
Author

maxfornacon commented Sep 14, 2024

This fixed it for me too. Thanks!

But why did it only happen when I applied the filter? When the realtime subscription printed out the received change it looked like this:

PostgresChangePayload(schema: ..., table: notifications, commitTimestamp: 2024-09-14 14:21:48.288Z, eventType: PostgresChangeEvent.delete, newRow: {}, oldRow: {id: 79575cff-c09b-4588-9556-83e1190de528}, errors: null)

So the old record was received and only the id of it. That indicates that it was set to full as it says int the docs:

When RLS is enabled and replica identity is set to full on a table, the old record contains only the primary key(s).

@dshukertjr
Copy link
Member

My guess is it's related to this update: supabase/walrus#76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working realtime This issue or pull request is related to realtime
Projects
None yet
Development

No branches or pull requests

2 participants