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

Crash when empty list is used in prepared statement #128

Closed
dysphie opened this issue Jan 30, 2025 · 7 comments
Closed

Crash when empty list is used in prepared statement #128

dysphie opened this issue Jan 30, 2025 · 7 comments
Assignees
Labels
bug Something isn't working reproduced

Comments

@dysphie
Copy link

dysphie commented Jan 30, 2025

The library crashes without any errors when empty lists are used in a prepared statement

await conn.run(`
  CREATE TABLE IF NOT EXISTS performances (
    id INTEGER PRIMARY KEY DEFAULT nextval('performance_id'),
    mutators VARCHAR[],
    tags VARCHAR[]
  );
`);

await conn.run(`
    INSERT INTO performances (mutators, tags)
    VALUES ($mutators, $tags)`, {
    mutators: listValue([]), // <--
    tags: listValue([])
});

console.log('never prints')
@jraymakers jraymakers self-assigned this Jan 30, 2025
@jraymakers jraymakers added bug Something isn't working reproduced labels Jan 30, 2025
@jraymakers
Copy link
Contributor

Thanks for the report! This is indeed a bug. I have an idea where it might be. Here's an even simpler repro:

const prepared = await connection.prepare('select ?');
prepared.bindList(1, listValue([]), LIST(INTEGER));

@jraymakers
Copy link
Contributor

Merged a fix. I'll get a release out soon.

@jraymakers
Copy link
Contributor

Fixed in 1.1.3-alpha.11.

@dysphie
Copy link
Author

dysphie commented Jan 30, 2025

Thank you! Although it appears to still crash in some scenarios:

await conn.run('select $a', { 'a': listValue([]) })

This doesn't happen when types are specified:

await conn.run('select $a', { 'a': listValue([]) }, { 'a': LIST(VARCHAR) })

@jraymakers
Copy link
Contributor

Sure enough. I'll investigate that additional case.

@jraymakers
Copy link
Contributor

Merged a fix. It'll go out with the next release; I'll do that soon, but there one more issue I want to investigate first.

@jraymakers
Copy link
Contributor

Published 1.1.3-alpha.12 with the second fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproduced
Projects
None yet
Development

No branches or pull requests

2 participants