Skip to content

Conversation

@mrj0
Copy link
Contributor

@mrj0 mrj0 commented Dec 20, 2025

Closes #17

The in-list expansion previously didn't consider if the argument wasn't a slice and ran into a panic when trying to expand the list.

Alternatively, this fix could have tried to detect and not consider subselects as inIn, but I don't know off-hand what else that might break. The code is looking back for in and potentially look forward if the next word is select. But stuff like that feels brittle and I don't know all the possible sql expressions that might be looked for. Alternatively, it could look for the next token being QuestionMark, but that would break valid in-lists like in ('a', ?).

Copy link
Contributor

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor remark, otherwise 👍

bind.go Outdated
Comment on lines 215 to 217
if !inIn || !argMeta.v.IsValid() {
// this QuestionMark is not in an in-list that needs expansion.
// if v is invalid, then the arg isn't a slice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is good, but maybe it's time to give meaningful names to these variable

Suggested change
if !inIn || !argMeta.v.IsValid() {
// this QuestionMark is not in an in-list that needs expansion.
// if v is invalid, then the arg isn't a slice
isSlice := argMeta.v.IsValid()
if !needExpansion || !isSlice {

Anything like that. The comments could remain my point is to use variables with meaningful names

@mrj0 mrj0 merged commit f10f9d2 into main Dec 29, 2025
10 checks passed
@mrj0 mrj0 deleted the mj/in-list-panic branch December 29, 2025 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic when using sqlx.In

2 participants