-
-
Notifications
You must be signed in to change notification settings - Fork 179
Description
Hey all!
Was going to post an issue but remembered this was here! I've found a solution to my problem, but wanted to post here as info for someone that may stumble upon this as well, and also to get it across the eyes of Hayes if you think something needs to be changed or if you think its good as is!
I encountered an error after performing an insert, which I discovered was related to a read-after-write inconsistency wherein drizzle inserted the record into the primary (write) database instance, and, immediately after, performed a read to return the newly created record from the read replica instance. Because of the replication lag between our (aws rds) instances in the cluster (~10-100ms), the read couldn't find the fresh record as it was not yet in the read replica.This resulted in the following error:
Model foo(foo's id) not found
My solution was just to override the specific drizzle query to use the primary db for both the read and write like so:
await db.$primary // $primary is the only addition
.insert(foo)
.values({
...values
})
.returning();After looking into this some more, we've realized that it's actually likely drizzleWithFieldInput that's causing this extra select, as we have an update mutation that's doing very similar logic, but just with fieldWithInput (which does not make an extra select)...
Originally posted by @MMShep97 in #1439 (comment)