-
Notifications
You must be signed in to change notification settings - Fork 305
Open
Description
Environment
- Electric server:
electricsql/electric:latest(self-hosted on Railway) - Feature flags:
ELECTRIC_FEATURE_FLAGS=allow_subqueries,tagged_subqueries - Client packages:
@electric-sql/pglite-sync: 0.4.1@electric-sql/pglite: 0.3.15@electric-sql/client: 1.4.0
- Using
syncShapeToTablefrom@electric-sql/pglite-sync
Description
We're building a multi-tenant app where users belong to workspaces. We need to sync profiles of all users in the same workspace as the current user.
Our WHERE clause for the profiles shape uses a subquery:
id IN (SELECT user_id FROM workspace_members WHERE workspace_id = 'known_workspace_id')The issue: When a new user joins the workspace (new row inserted into workspace_members), their profile does NOT sync to existing workspace members - even with tagged_subqueries enabled, even after client-side refresh.
Steps to Reproduce
- User A creates a workspace and starts syncing profiles
- User B (already has a profile) is added to User A's workspace via direct SQL insert
- User A's
workspace_membersshape updates (shows 5 members) - User A's
profilesshape does NOT update (still shows 4 profiles) - Client detects mismatch, triggers refresh (stops sync, clears table, clears Electric metadata, restarts)
- Even after refresh, the new profile is not returned
Relevant logs
[collections] workspace_members row count after sync: 5
[collections] profiles row count after sync: 5
[collections] useWorkspaceSettings: querying profiles for IDs: Array(5)
[collections] useWorkspaceSettings: profilesResult returned: Array(4) // missing the new member!
[collections] useWorkspaceSettings: missing 1 profiles, refreshing...
[collections] refreshTables called for: profiles
[collections] stopped sync for profiles (refresh)
[collections] cleared profiles for refresh
[collections] cleared Electric metadata for profiles
[collections] restarting sync for profiles
[collections] initial sync complete for profiles
[collections] profilesResult returned: Array(4) // STILL missing after fresh sync!
Schema (simplified)
CREATE TABLE profiles (
id UUID PRIMARY KEY,
email TEXT
);
CREATE TABLE workspace_members (
id UUID PRIMARY KEY,
workspace_id UUID NOT NULL,
user_id UUID NOT NULL REFERENCES profiles(id),
role TEXT NOT NULL
);Questions
Per RFC #2931 and @balegas's comment, tagged_subqueries should "handle reactivity if any data arrives in the inner query." Our inner query is workspace_members WHERE workspace_id = 'X', and when new rows are inserted, the outer profiles shape should update.
- Does
tagged_subqueriesactually re-evaluate subqueries when dependent tables change? - Why does a fresh shape request (new sync after clearing metadata) still not return the newly matching row?
- Is the subquery result cached somewhere on the Electric server that persists across client reconnects?
Thanks for any guidance!
Metadata
Metadata
Assignees
Labels
No labels