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

False positive: db.Queryx #35

Open
pellared opened this issue Feb 8, 2024 · 4 comments
Open

False positive: db.Queryx #35

pellared opened this issue Feb 8, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@pellared
Copy link

pellared commented Feb 8, 2024

Version: v0.5.1

Repro steps:

package bug_test

import (
	"log"

	"github.com/jmoiron/sqlx"
)

func Example() {
	db, err := sqlx.Open("pgx", "postgres://localhost/db")
	if err != nil {
		log.Print(err)
		return
	}
	defer db.Close()

	rows, err := db.Queryx("SELECT * FROM users")
	if err != nil {
		log.Print(err)
		return
	}
	defer rows.Close()
}

Result (from golangci-lint):

example_test.go:17:24: Rows/Stmt/NamedStmt was not closed (sqlclosecheck)
        rows, err := db.Queryx("SELECT * FROM users")
@shubhamzanwar
Copy link

➕1

we're facing the same issue in our workflows

@ryanrolds
Copy link
Owner

Thank you for the report. I will take a look at this over the next few days.

@ryanrolds ryanrolds added the bug Something isn't working label Feb 8, 2024
@shubhamzanwar
Copy link

How's it looking with this one? 🙏🏽

@Bodyancheq
Copy link

Bodyancheq commented Mar 7, 2024

+1
in my project following code worked as a solution:

rows, err := db.Queryx("SELECT * FROM users")
if err != nil {
  log.Print(err)
  return
}
defer func() {
  _ = rows.Close()
}()

also worth mentioning: when I used sql instead of sqlx, there was no error

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

No branches or pull requests

4 participants