Incredibly cryptic error when running DB transaction
I have this piece of code:
And it keeps causing this cryptic error every time it's run:
The error goes away when I comment out the second line, but I don't understand why. The update call is supposed to just not find any entries matching the query (given the current state of my DB) and simply update nothing, but instead it errors out.
7 Replies
You can make a minimal reproduction and it will be easier to look at it. As for me I don’t see why it errors out
@Valerka clone this branch: https://github.com/cubing/cubingcontests.com/tree/auth. I am running this with Deno and Docker compose. From the root of the project, run ./bin/start-dev.sh, which starts the frontend, drizzle studio and the Postgres DB with Docker Compose. Go to localhost:3000 and log in using username "admin" and password "cc". Then click the green button "Scramble" on the home page. This calls the Next JS server function that has that block of Drizzle code, and it should produce the error. Note that this exact code worked before, but now it's broken for some reason.
By minimal reproduction i meant this(https://en.wikipedia.org/wiki/Minimal_reproducible_example)
If you can make just one separate typescript file where you define drizzle schemas and this query then i can try to take a look.
Otherwise the issue might be not even related to drizzle...
I am not expert in drizzle though
Minimal reproducible example
In computing, a minimal reproducible example (abbreviated MRE) is a collection of source code and other data files that allow a bug or problem to be demonstrated and reproduced. The important feature of a minimal reproducible example is that it is as small and as simple as possible, such that it is just sufficient to demonstrate the problem, but...
Between, check this out:
https://github.com/drizzle-team/drizzle-orm/issues/956#issuecomment-2198759342
Do you have
Since you said for update statement it errors
This one could be the reason: https://github.com/cubing/cubingcontests.com/blob/auth/client/server/db/schema/collective-solutions.ts#L22
It has .$onUpdate(() => sql
now()
),Omg, that was totally it! Thank you so much!
I was just about done with my minimal reproduction too, haha
Once I removed the part with that sql statement, it started working again
@Valerka should I use new Date() instead of sql`now()`?
I dunno if it's the right way to do it, but at least it worked and updated the time. Thanks a lot, once again.
If you check this example: https://orm.drizzle.team/docs/latest-releases/drizzle-orm-v0305
In docs they use
Date
But i do not understand why in your case now()
does not work, because in my case i use $onUpdate(() => sqlnow()
), and it works fine for me, though i use drizzle-orm@beta
which more closely aligns with what drizzle 1.0 will beDrizzle ORM - DrizzleORM v0.30.5 release
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Oh, maybe they fixed it in the Beta