Skip to content

Commit dbbb166

Browse files
committed
chore: read pgvector test assertions from primary to fix read-replica flake
The vector column tests read query results through the raw payload.db.drizzle handle right after payload.create(). That handle is wrapped by withReplicas(), so its reads default to a replica and bypass payload's read-after-write routing, returning stale/empty rows on the postgres-read-replica adapter. Read through payload.db.primaryDrizzle (falling back to drizzle when no replicas are configured) so the assertions see the just-written rows.
1 parent 9d946ac commit dbbb166

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

test/database/postgres-vector.int.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ describePostgres('postgres vector custom column', () => {
112112

113113
const similarity = sql<number>`1 - (${cosineDistance(payload.db.tables.posts.embedding, catEmbedding)})`
114114

115-
const db = payload.db.drizzle as PostgresDB
115+
// Read through the primary. `payload.db.drizzle` is the withReplicas() handle, whose
116+
// reads default to a replica; querying it right after a write races replication lag.
117+
const db = (payload.db.primaryDrizzle ?? payload.db.drizzle) as PostgresDB
116118

117119
const res = await db
118120
.select()
@@ -234,7 +236,9 @@ describePostgres('postgres vector custom column', () => {
234236

235237
const distance = sql<number>`(${l2Distance(payload.db.tables.posts.embedding, catEmbedding)})`
236238

237-
const db = payload.db.drizzle as PostgresDB
239+
// Read through the primary. `payload.db.drizzle` is the withReplicas() handle, whose
240+
// reads default to a replica; querying it right after a write races replication lag.
241+
const db = (payload.db.primaryDrizzle ?? payload.db.drizzle) as PostgresDB
238242

239243
const res = await db
240244
.select()
@@ -346,7 +350,9 @@ describePostgres('postgres vector custom column', () => {
346350

347351
const similarity = sql<number>`1 - (${jaccardDistance(payload.db.tables.posts.embedding, catEmbedding)})`
348352

349-
const db = payload.db.drizzle as PostgresDB
353+
// Read through the primary. `payload.db.drizzle` is the withReplicas() handle, whose
354+
// reads default to a replica; querying it right after a write races replication lag.
355+
const db = (payload.db.primaryDrizzle ?? payload.db.drizzle) as PostgresDB
350356

351357
const res = await db
352358
.select()

0 commit comments

Comments
 (0)