Strange error while inserting
With 0.28.2, I'm having a strange issue which always occur with a specific value being inserted. I tried removing plugins, but that didn't help either.
the error:
The query:
Where
chunk
is an array of POJOs with 3 properties. I have a custom onConflict callback but even without it, the query still fails.
The strange thing about it, is that it only happens when I insert a particular POJO. I tried chunking the insert into only 1 POJO at a time, and it works for every POJO except for a particular one, which of course, has nothing different from others... (can't show the actual values though).
Example values:
12 Replies
This is the rest of the stack trace
I noticed the faulty value is the last one of the array. Perhaps more strangely, if I reverse the array (chunk) of values, no errors are thrown, even if the faulty value is right there, at front, as the first value of the array
So I guess it's not about the value itself...
That
chunk
is wrapped in a javascript Proxy
, that seems misconfigured somehow.
The query compiler is trying to get the first value out of the array, and the proxy blows upI tried both passing the
chunk
as it is (which btw is the result of a previous select query) and creating an anonymous object on the fly via
Either way, the same error happens. If my chunk is 1 value long, only the last one chunk gives me such error, cause I also tried splitting the query into multiple insert of chunks of size 1.
The last one chunk, only if it has those previously described values, that is:
Kysely doesn't use proxies anywhere. The error comes from this code:
The failing row is
this.visitNode(nodes[i])
Is something in your setup monkey-patching Object.freeze
?
That nodes
array is actually a list of internal nodes and not the list you pass in. So the issue is not your input after all.
But kysely wraps all those node lists with Object.freeze
.
For shits and giggles, try to do this somewhere before the failing code
Thanks a lot, I’ll try digging a bit more
Hey 👋
Effect is patching everything.
Anti pattern.
Ok so you think there’s something going on with their patching thing, gotcha, must be
Stack trace points at the library they implemented to make Kysely "effectful"
I opened a "ticket" on their discord too 🙂
https://discord.com/channels/795981131316985866/1389230820790763571
I would love to suggest improvements to handle all of this in the effect package. What are the "normal" ways to execute queries? Cause right now they're patching cause they basically "await" a query and it makes it to execute it (losing
executeTakeFirst
behaviors and such while doing this), but I was right there to suggest to wrap queries to make them executable, so not to have to patch anything and just do what the builders already do internally when you call execute
or executeTakeFirst
and so onIf someone's interested I opened a PR in effect codebase to discuss how to improve patching (basically avoiding patching) https://github.com/Effect-TS/effect/pull/5156#issue-3200113137
GitHub
wip: effect sql kysely new proposal by kristiannotari · Pull Reque...
Type
Refactor
Feature
Bug Fix
Optimization
Documentation Update
Description
This proposal (or suggestion of a proposal) is there to make working with Kysely less prone to errors, due to th...
always nice seeing a lot of code being deleted.
They did the patching thing to make it easier for deevlopers to use kysely with effect, I get the why. I don't like patching, proxies, prototypes and stuff, hard to maintain, easy to make mistakes, as you can see from this help post.
I started it more as a "let's address this" than as a "here it is the final solution". There's a bunch of things missing, namely transactions and "effect" client usage under the hood. I don't know much of how they structured the sql packages, so can't help much there, let's see if someone picks it up