electric-sql / electric

Sync little subsets of your Postgres data into local apps and services.
https://electric-sql.com
Apache License 2.0
6.42k stars 154 forks source link

Successfull local change fail on remote #866

Closed JosselinTILLAY closed 6 months ago

JosselinTILLAY commented 9 months ago

Hello everyone.

I have a very simple entity name "synchro_entity" with 2 fields : label and guid. Label is a text and guid is an uuid.

I made a simple react-native app to try to sync it between a local SQLite and a remote PG. The app just display all "synchro_entity" and allow updating the label.

For now, I have only one entity with "e1" as label, and I want to change it.

When I call db.synchro_entity.update, the update is successfull locally (if i kill the app and return on it, the changes are saved) but the remote database isn't updated.

In the db logs, I have this : ERROR: invalid input syntax for type uuid: "e1"

Here is the full log :

poc-electricsql-db-1        | 2024-01-22 13:56:32.670 UTC [244] ERROR:  invalid input syntax for type uuid: "e1"
poc-electricsql-db-1        | 2024-01-22 13:56:32.670 UTC [244] CONTEXT:  PL/pgSQL function electric.perform_reordered_op___public__synchro_entity(electric.shadow__public__synchro_entity) line 30 at SQL statement
poc-electricsql-db-1        |   SQL statement "SELECT electric.perform_reordered_op___public__synchro_entity(NEW)"
poc-electricsql-db-1        |   PL/pgSQL function electric.resolve_observed_tags___public__synchro_entity() line 32 at PERFORM
poc-electricsql-db-1        |   SQL statement "INSERT INTO electric.shadow__public__synchro_entity (_last_modified, _tag, _tags, guid, _tag_label)  
poc-electricsql-db-1        |                   VALUES (pg_current_xact_id()::text::bigint, NEW._tag, ARRAY[NEW._tag], NEW.guid, NEW._tag)
poc-electricsql-db-1        |                   ON CONFLICT (guid) DO UPDATE
poc-electricsql-db-1        |                       SET _currently_reordering = NULL,
poc-electricsql-db-1        |                           _last_modified = pg_current_xact_id()::text::bigint,
poc-electricsql-db-1        |                           _tag = NEW._tag,
poc-electricsql-db-1        |                           _is_a_delete_operation = NEW._is_a_delete_operation,
poc-electricsql-db-1        |                           _observed_tags = NEW._observed_tags,
poc-electricsql-db-1        |                           _modified_columns_bit_mask = NEW._modified_columns_bit_mask"
poc-electricsql-db-1        |   PL/pgSQL function electric.shadow_insert_to_upsert___public__synchro_entity() line 7 at SQL statement
poc-electricsql-db-1        | 2024-01-22 13:56:32.673 UTC [1] LOG:  background worker "logical replication worker" (PID 244) exited with exit code 1
poc-electricsql-db-1        | 2024-01-22 13:56:32.673 UTC [250] LOG:  logical replication apply worker for subscription "postgres_1" has started

It look like it try to match the guid with the label.

The issue don't seem to come from the React-Native app because the local change is successfull.

linear[bot] commented 9 months ago

VAX-1561 Successfull local change fail on remote

JosselinTILLAY commented 9 months ago

Ok, i found why. My guid field was in second position, not first. If i drop everything and change the column order, it work.

alco commented 9 months ago

Hey @JosselinTILLAY. I'm curious about the column ordering issue you saw. What did the full call to db.synchro_entity.update() looked like? Our client APIs work with named fields so column ordering is not an issue, generally speaking.

JosselinTILLAY commented 9 months ago

Here is my update :

db.synchro_entity.update({
  data: {
    label: label
  },
  where: {
    guid: synchro_entity.guid,
  },
});

where synchro_entity come from a liveMany from a parent component.