Skip to content
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

QueryCompilerError: Could not serialize value causes Kysely instance to fail later #1028

Closed
mdnorman opened this issue Jun 6, 2024 · 2 comments
Labels
bug Something isn't working greenlit Ready for implementation

Comments

@mdnorman
Copy link

mdnorman commented Jun 6, 2024

The following code will cause an error and then break the DB connection for further updates.

const DB = new Kysely<Database>(...);

const someIds = [undefined]; // oops!
const otherId = 1234;

try {
  await db.selectFrom("a").where("id", "in", someIds).execute(),
} catch(e) {
  // e is "QueryCompilerError: Could not serialize value" because of the undefined

  await db.updateTable("b").where("id", "=", otherId).set({ status: "error" }).execute();
  // line above throws another error because the generated SQL is 
  // "(update "b" set "status" = :0 where "id" = :1)"
  // notice the parentheses around the generated SQL
}

I confirmed that restarting the service and running the update call works fine because the generated SQL does not have the surrounding parentheses. I confirmed the presence of the parentheses with query.compile().sql.

@koskimas koskimas added bug Something isn't working greenlit Ready for implementation labels Jun 7, 2024
@koskimas
Copy link
Member

koskimas commented Jun 7, 2024

Ouch, thanks for opening the issue! We don't clear the OperationNodeVisitor.nodeStack at the beginning of compilation. The stack is left behind from that interrupted compilation.

But that query shouldn't pass typescript checks. The type of the array is undefined[]. Even if the type was (string | undefined)[] Kysely wouldn't accept it. Are you using some extremely loose typescript settings? Strict mode is needed for Kysely types to function properly.

https://kyse.link/C43WH

@mdnorman
Copy link
Author

mdnorman commented Jun 7, 2024

Yep, you're absolutely right about the types. This was a simple repro to demonstrate the problem, but in the real case, the undefined sneakily got in there from a much earlier part of the pipeline.

thecodrr pushed a commit to thecodrr/kysely that referenced this issue Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working greenlit Ready for implementation
Projects
None yet
Development

No branches or pull requests

2 participants