Skip to content

fix(drizzle): upsert row error when using read replicas #13023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sam-gab
Copy link
Contributor

@sam-gab sam-gab commented Jul 3, 2025

As highlighted in this issue, retrieving a newly created row when using read replicas will sometimes fail as there is usually some lag time between replication.

@sam-gab sam-gab changed the title Fix/upsert with read replica fix(drizzle): upsert row error when using read replicas Jul 3, 2025
Comment on lines +494 to +497
if (!doc) {
return { ...data, ...insertedRow } as T
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's the best way to handle this.
The returned data can miss a lot of information or have it in a different shape (because the transform function doesn't run here).
Would skip of using read replicas for that db.query call help here? I guess so.

Copy link
Contributor Author

@sam-gab sam-gab Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @r1tsuu, yes I thought about skipping read replica here and just reading from the primary. But I had 2 issues:

  1. I wasn't exactly sure how to do it here as the db.query[xxxx] object wasn't type hinted, and I guess didn't also want to spend too much time figuring it out due to the second issue below.
  2. I wondered if that would also defeat the purpose of using a read replica – considering a use-case of high volume ingestion.

So this was just an attempt at a workaround, and hopefully get you guys to pick up this issue - as it is really making the whole read-replica feature unusable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the transform function doesn't run here

Can I also run the transform and use the { ...data, ...insertedRow } as a fallback for the nullable doc instead of just returning it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants