supabase-flutter icon indicating copy to clipboard operation
supabase-flutter copied to clipboard

Listen to data using the .eq filter not working properly

Open jvlt opened this issue 2 years ago • 9 comments

Describe the bug Maybe I am missing something, but there seems to be a bug when using the .eq filter in streaming data via realtime.

To Reproduce Steps to reproduce the behavior:

  1. Create a table with at least one additional column (I set it to type boolean and called it col)
  2. Add some mock data
  3. Use the SDK to retrieve data with an .eq filter: supabase.from('example').stream(primaryKey: ['id']).eq('col', true);

Expected behavior Lets say there are 2 rows where col is true. These two are delivered to the device and an event is registered everytime something changes in these rows. So far so good. But: If a different row gets col set to true, the SDK throws the following error: Unhandled Exception: Exception: Could not find the updated record. The expected behavior would be for the SDK to deliver 3 rows.

Furthermore, if a row A that previously had col = true gets set to col = false, there is no event emitted. Additionally, if something changes in a row where col is still set to true, the row A will still be emitted in the event, but in the state before col was set to false.

Smartphone (please complete the following information): Version: supabase_flutter: ^1.2.1

Additional context Complete error message:

E/flutter (10388): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Could not find the updated record.
E/flutter (10388): #0      SupabaseStreamBuilder._addException (package:supabase/src/supabase_stream_builder.dart:404:67)
E/flutter (10388): supabase/realtime#1      SupabaseStreamBuilder._getStreamData.<anonymous closure> (package:supabase/src/supabase_stream_builder.dart:295:9)
E/flutter (10388): supabase/realtime#2      RealtimeChannel.trigger (package:realtime_client/src/realtime_channel.dart:559:22)
E/flutter (10388): supabase/realtime#3      RealtimeClient.onConnMessage.<anonymous closure>.<anonymous closure> (package:realtime_client/src/realtime_client.dart:294:41)
E/flutter (10388): supabase/realtime#4      Iterable.forEach (dart:core/iterable.dart:325:35)
E/flutter (10388): supabase/realtime#5      RealtimeClient.onConnMessage.<anonymous closure> (package:realtime_client/src/realtime_client.dart:294:12)
E/flutter (10388): supabase/realtime#6      new RealtimeClient.<anonymous closure> (package:realtime_client/src/realtime_client.dart:100:21)
E/flutter (10388): supabase/realtime#7      RealtimeClient.onConnMessage (package:realtime_client/src/realtime_client.dart:277:11)
E/flutter (10388): supabase/realtime#8      RealtimeClient.connect.<anonymous closure> (package:realtime_client/src/realtime_client.dart:125:22)
E/flutter (10388): supabase/realtime#9      _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (10388): supabase/realtime#10     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (10388): supabase/realtime#11     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (10388): supabase/realtime#12     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (10388): supabase/realtime#13     _HandleErrorStream._handleData (dart:async/stream_pipe.dart:253:10)
E/flutter (10388): supabase/realtime#14     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (10388): supabase/realtime#15     _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (10388): supabase/realtime#16     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (10388): supabase/realtime#17     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (10388): supabase/realtime#18     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
E/flutter (10388): supabase/realtime#19     _StreamController._add (dart:async/stream_controller.dart:648:7)
E/flutter (10388): supabase/realtime#20     _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (10388): supabase/realtime#21     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (10388): supabase/realtime#22     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (10388): supabase/realtime#23     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
E/flutter (10388): supabase/realtime#24     _StreamController._add (dart:async/stream_controller.dart:648:7)
E/flutter (10388): supabase/realtime#25     _StreamController.add (dart:async/stream_controller.dart:596:5)
E/flutter (10388): supabase/realtime#26     new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1144:21)
E/flutter (10388): supabase/realtime#27     _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (10388): supabase/realtime#28     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (10388): supabase/realtime#29     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (10388): supabase/realtime#30     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
E/flutter (10388): supabase/realtime#31     _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
E/flutter (10388): supabase/realtime#32     _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:332:23)
E/flutter (10388): supabase/realtime#33     _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:226:46)
E/flutter (10388): supabase/realtime#34     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
E/flutter (10388): supabase/realtime#35     _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (10388): supabase/realtime#36     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (10388): supabase/realtime#37     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (10388): supabase/realtime#38     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
E/flutter (10388): supabase/realtime#39     _StreamController._add (dart:async/stream_controller.dart:648:7)
E/flutter (10388): supabase/realtime#40     _StreamController.add (dart:async/stream_controller.dart:596:5)
E/flutter (10388): supabase/realtime#41     _Socket._onData (dart:io-patch/socket_patch.dart:2324:41)
E/flutter (10388): supabase/realtime#42     _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (10388): supabase/realtime#43     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (10388): supabase/realtime#44     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (10388): supabase/realtime#45     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
E/flutter (10388): supabase/realtime#46     _StreamController._add (dart:async/stream_controller.dart:648:7)
E/flutter (10388): supabase/realtime#47     _StreamController.add (dart:async/stream_controller.dart:596:5)
E/flutter (10388): supabase/realtime#48     _RawSecureSocket._sendReadEvent (dart:io/secure_socket.dart:1107:19)
E/flutter (10388): supabase/realtime#49     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (10388): supabase/realtime#50     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (10388): supabase/realtime#51     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (10388): supabase/realtime#52     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

jvlt avatar Jan 06 '23 12:01 jvlt

Thanks @jvlt for opening this issue. Yup, that behavior is buggy. I will fix it right now!

dshukertjr avatar Jan 06 '23 16:01 dshukertjr

Just to break down the issue, this is an issue on the SDK side, and can be fixed with the PR above.

Lets say there are 2 rows where col is true. These two are delivered to the device and an event is registered everytime something changes in these rows. So far so good. But: If a different row gets col set to true, the SDK throws the following error: Unhandled Exception: Exception: Could not find the updated record. The expected behavior would be for the SDK to deliver 3 rows.

This on the other hand is happening due to the current limitation on our realtime server. I have opened an issue here, so let's see if there is a way to work around it.

Furthermore, if a row A that previously had col = true gets set to col = false, there is no event emitted. Additionally, if something changes in a row where col is still set to true, the row A will still be emitted in the event, but in the state before col was set to false.

dshukertjr avatar Jan 06 '23 16:01 dshukertjr

Thanks @dshukertjr! Is there something that can be done in the SDK regarding the fact that a row not matching the equality condition is still included in the data set?

jvlt avatar Jan 07 '23 11:01 jvlt

Since I am creating graphics for something else, I may as well just put them here too:

Current behavior:

Desired behavior:

Where A and B are rows and Result is the stream provided by the SDK.

jvlt avatar Jan 07 '23 12:01 jvlt

@jvlt

Is there something that can be done in the SDK regarding the fact that a row not matching the equality condition is still included in the data set?

There probably isn't anything we can do on the client side. Because the server does not emit the fact that the row went from true to false, there is no way for the client to know that and stop emitting it as a stream.

dshukertjr avatar Jan 08 '23 01:01 dshukertjr

if a row A that previously had col = true gets set to col = false, there is no event emitted

@jvlt what did you end up doing to track this?

w3b6x9 avatar Jan 18 '23 23:01 w3b6x9

I do have same problem when using stream with .eq though as mine is reading inside to a json data

 base.from("monitoring_sheet")
    .stream(primaryKey: ["id"])
       .eq("some_id->>my_id","36sth26537")

it wont stream whenever i change in the db it won't listen is there a way to fix this?

Erchil66 avatar Jan 25 '23 07:01 Erchil66

@Erchil66 That seems like a separate issue. Would you be able to open a separate issue for it?

dshukertjr avatar Jan 25 '23 07:01 dshukertjr

Sure, @dshukertjr

Erchil66 avatar Jan 25 '23 15:01 Erchil66