D1 database not updating row that exists

For Workers & Pages, what is the name of the domain?

auth…app

What is the issue or error you’re encountering

I am getting random RETURNING Behaviour on D1

What steps have you taken to resolve the issue?

This error happens sporadically when I run my unit tests against the API and I think it may be a replication issue on D1, however that doesn’t make sense as when my worker receives the request, it first checks the row exists and finds it, but then in the same request running the following update to update the same row:

const result = await DB.prepare(
UPDATE refresh_tokens SET token = ?, modified_on = CURRENT_TIMESTAMP WHERE id = ? RETURNING *;
)
.bind(token.token, token.id)
.run()

Doesn’t return any result sporadically with the following result:

result:

{
success: true,
meta:
{
served_by: “v3-prod”,
served_by_region: “WNAM”,
served_by_primary: true,
timings: {
sql_duration_ms: 0.2475,
},
duration: 0.2475,
changes: 0,
last_row_id: 38,
changed_db: false,
size_after: 159744,
rows_read: 2,
rows_written: 0,
},
results:

Can anyone help explain why this would happen sporadically when I’ve already read to check the row exists in my request before updating? And anything I can do to prevent this issue as its causing my app unit tests to fail randomly sometimes.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.