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

Unexpected behavior in realtime events in Flutter android app #706

Open
B0yma opened this issue Oct 24, 2023 · 2 comments
Open

Unexpected behavior in realtime events in Flutter android app #706

B0yma opened this issue Oct 24, 2023 · 2 comments
Labels
bug Something isn't working realtime This issue or pull request is related to realtime

Comments

@B0yma
Copy link

B0yma commented Oct 24, 2023

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

Unexpected behavior in flutter android app. in some cases realtime events on update not fired. in some cases fired with wrong data

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. create table with rls policy
create table
  public.test (
    id bigint generated by default as identity,
    some_int bigint null,
    constraint test_pkey primary key (id)
  ) tablespace pg_default;
  
  BEGIN;
  ALTER POLICY "Enable read access for all users" ON "public"."test" USING ((some_int >= 1));
COMMIT;
  1. put rows with some_int - [0, 1, 2]

  2. run flutter app with your secrets

Future<void> main() async {
  final supabase = await Supabase.initialize(
    url: supabaseUrl,
    anonKey: supabaseAnonKey,
  );
  runApp(MyApp(supabase: supabase));
}

class MyApp extends StatelessWidget {

  final Supabase supabase;
  const MyApp( {super.key, required this.supabase});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: StreamBuilder<List<int>>(
        stream: getSomeInts(),
        initialData: const [],
        builder: (context, snapshot) {
          return const FlutterLogo();
        }
      )
    );
  }

  Stream<List<int>> getSomeInts() {
    return supabase.client.from('test').stream(primaryKey: ['id']).map((event) {
      log("event.toString():$event");
      return event.map((e) => e['some_int'] as int).toList();
    });
  }
}

you will see in log

event.toString():[{id: 2, some_int: 1}, {id: 3, some_int: 2}]
  1. change in supbase some_int from 0 -> 3
    you will see in log
event.toString():[{id: 2, some_int: 1}, {id: 3, some_int: 2}, {id: 1, some_int: 3}]
  1. change in supbase some_int from 3 -> 0
    log not fires

Expected behavior

event fires

  1. change in supbase some_int from 1 -> 3
    you will see in log
event.toString():[{id: 2, some_int: 3}, {id: 3, some_int: 2}, {id: 1, some_int: 3}]

its wrong data

Expected behavior

correct data [0,3,2]

Screenshots

image
image

System information

  • OS: Windows 10

Additional context

flutter doctor

  • Doctor summary (to see all details, run flutter doctor -v):
  • [√] Flutter (Channel stable, 3.13.6, on Microsoft Windows [Version 10.0.19045.2251]
  • Android Studio (version 2022.3)

version of supabse in pubspec of flutter

  • supabase_flutter: ^1.10.23

device

  • android emulator api33_x86_64
@B0yma B0yma added the bug Something isn't working label Oct 24, 2023
@dshukertjr dshukertjr transferred this issue from supabase/supabase Nov 13, 2023
@B0yma
Copy link
Author

B0yma commented Dec 1, 2023

up

@dshukertjr
Copy link
Member

This is the expected behavior currently.

Because you have set the RLS so that some_int less than 1 is not readable, the update on step 5 is not readable from the client.

We are going to need to wait for the fix on the server side for events like this to be sent to the client.
Related supabase/walrus#64

@dshukertjr dshukertjr added the realtime This issue or pull request is related to realtime label Dec 2, 2023
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