Skip to content

Using a bytea and Realtime leads to a double-encoded result #1180

Open
@gagik

Description

@gagik

Describe the bug
I store data in a bytea column and subscribe to it using Realtime. Simply storing data with

String _bytesToHex(Uint8List bytes) {
    final buffer = StringBuffer();
    for (final byte in bytes) {
      buffer.write(byte.toRadixString(16).padLeft(2, '0'));
    }
    return buffer.toString();
  }i

await _supabase.from('test').upsert({
 'data': '\\x${_bytesToHex(Uint8List([1, 2, 3])}', /
})

// This is fine
_hexToBytes(await _supabase.from('test').upsert({
 'data': '\\x${_bytesToHex(Uint8List([1, 2, 3])}', /
}).select());

leads to a consistent result in the Supabase dashboard as well as when trying to retrieving it using a SELECT.

However, when I have a subscription to this table, i.e.

 _backendSubscription?.onPostgresChanges(
        schema: publicSchema,
        table: _backendTables[syncable],
        event: PostgresChangeEvent.all,
        callback: (p) {
         // This is wrong... prints out a doubly hex-encoded string binary...
         print(_hexToBytes(p['data']));
        },

The resulting record has a double encoded field, leading me to manually patch it every time which seems wrong.

To Reproduce
Steps to reproduce the behavior:

  1. Start a Realtime subscription on a table with bytea column.
  2. Add a new record.
  3. Print the bytea column.

Expected behavior
A hex representation of the binary data in the table.

Actual
A hex representation of the hex representation of the binary data in the table.

Screenshots
If applicable, add screenshots to help explain your problem.
N/A

Version (please complete the following information):

├── supabase_flutter 2.9.0
│   ├── supabase 2.7.0
│   │   ├── functions_client 2.4.2
│   │   ├── gotrue 2.12.0
│   │   ├── postgrest 2.4.2
│   │   ├── realtime_client 2.5.0
│   │   ├── storage_client 2.4.0

Additional context
Add any other context about the problem here.

This may be server related and not SDK-specific.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrealtimeThis issue or pull request is related to realtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions