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:
TypeError: 'get' on proxy: property '0' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '#<Object>' but got '#<Object>')
TypeError: 'get' on proxy: property '0' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '#<Object>' but got '#<Object>')
The query:
db.insertInto(config.table).values(chunk).onConflict(oc => config.onConflict(oc)).returning(`$uuid`)
db.insertInto(config.table).values(chunk).onConflict(oc => config.onConflict(oc)).returning(`$uuid`)
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:
{
uuid: "43cacb0b-8786-4beb-b57a-f1099cf876fa",
status: "CHECKING",
priority: "1748610457.000000"
}
{
uuid: "43cacb0b-8786-4beb-b57a-f1099cf876fa",
status: "CHECKING",
priority: "1748610457.000000"
}
12 Replies
Kristian Notari
Kristian NotariOP2mo ago
This is the rest of the stack trace
at PostgresQueryCompiler.compileList (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-compiler/default-query-compiler.js:138:33)\n' +
at PostgresQueryCompiler.visitValues (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-compiler/default-query-compiler.js:223:14)\n' +
at PostgresQueryCompiler.visitNode (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/operation-node/operation-node-visitor.js:111:34)\n' +
at PostgresQueryCompiler.visitInsertQuery (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-compiler/default-query-compiler.js:195:18)\n' +
at PostgresQueryCompiler.visitNode (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/operation-node/operation-node-visitor.js:111:34)\n' +
at PostgresQueryCompiler.compileQuery (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-compiler/default-query-compiler.js:26:14)\n' +
at DefaultQueryExecutor.compileQuery (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-executor/default-query-executor.js:19:31)\n' +
at InsertQueryBuilder.compile (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-builder/insert-query-builder.js:1099:37)\n' +
at InsertQueryBuilder.executeCommit (/Users/<path-to-project>/node_modules/.pnpm/@effect+sql-kysely@0.33.10_@effect+sql@0.37.10_effect@3.16.5_kysely@0.28.2/node_modules/@effect/sql-kysely/src/internal/patch.ts:75:42)\n' +
at <anonymous> (/Users/<path-to-project>/node_modules/.pnpm/effect@3.16.5/node_modules/effect/src/internal/fiberRuntime.ts:1339:34)'
at PostgresQueryCompiler.compileList (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-compiler/default-query-compiler.js:138:33)\n' +
at PostgresQueryCompiler.visitValues (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-compiler/default-query-compiler.js:223:14)\n' +
at PostgresQueryCompiler.visitNode (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/operation-node/operation-node-visitor.js:111:34)\n' +
at PostgresQueryCompiler.visitInsertQuery (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-compiler/default-query-compiler.js:195:18)\n' +
at PostgresQueryCompiler.visitNode (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/operation-node/operation-node-visitor.js:111:34)\n' +
at PostgresQueryCompiler.compileQuery (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-compiler/default-query-compiler.js:26:14)\n' +
at DefaultQueryExecutor.compileQuery (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-executor/default-query-executor.js:19:31)\n' +
at InsertQueryBuilder.compile (/Users/<path-to-project>/node_modules/.pnpm/kysely@0.28.2/node_modules/kysely/dist/cjs/query-builder/insert-query-builder.js:1099:37)\n' +
at InsertQueryBuilder.executeCommit (/Users/<path-to-project>/node_modules/.pnpm/@effect+sql-kysely@0.33.10_@effect+sql@0.37.10_effect@3.16.5_kysely@0.28.2/node_modules/@effect/sql-kysely/src/internal/patch.ts:75:42)\n' +
at <anonymous> (/Users/<path-to-project>/node_modules/.pnpm/effect@3.16.5/node_modules/effect/src/internal/fiberRuntime.ts:1339:34)'
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...
koskimas
koskimas2mo ago
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 up
Kristian Notari
Kristian NotariOP2mo ago
I 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
chunk.map(value => ({
uuid: value.uuid,
status: value.status,
priority: value.priority
}))
chunk.map(value => ({
uuid: value.uuid,
status: value.status,
priority: value.priority
}))
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:
{
uuid: "43cacb0b-8786-4beb-b57a-f1099cf876fa",
status: "CHECKING",
priority: "1748610457.000000"
}
{
uuid: "43cacb0b-8786-4beb-b57a-f1099cf876fa",
status: "CHECKING",
priority: "1748610457.000000"
}
koskimas
koskimas2mo ago
Kysely doesn't use proxies anywhere. The error comes from this code:
const lastIndex = nodes.length - 1

for (let i = 0; i <= lastIndex; i++) {
this.visitNode(nodes[i])

if (i < lastIndex) {
this.append(separator)
}
}
const lastIndex = nodes.length - 1

for (let i = 0; i <= lastIndex; i++) {
this.visitNode(nodes[i])

if (i < lastIndex) {
this.append(separator)
}
}
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
Object.freeze = () => {}
Object.freeze = () => {}
Kristian Notari
Kristian NotariOP2mo ago
Thanks a lot, I’ll try digging a bit more
Igal (mobile)
Igal (mobile)2mo ago
Hey 👋 Effect is patching everything. Anti pattern.
Kristian Notari
Kristian NotariOP2mo ago
Ok so you think there’s something going on with their patching thing, gotcha, must be
Igal
Igal2mo ago
Stack trace points at the library they implemented to make Kysely "effectful"
Kristian Notari
Kristian NotariOP2mo ago
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 on
Kristian Notari
Kristian NotariOP2mo ago
If 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...
Igal (mobile)
Igal (mobile)2mo ago
always nice seeing a lot of code being deleted.
Kristian Notari
Kristian NotariOP2mo ago
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

Did you find this page helpful?