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

Find uses of Rows.Err when Rows is an interface #23

Merged
merged 2 commits into from
Oct 18, 2021

Conversation

coder543
Copy link

@coder543 coder543 commented May 24, 2021

I was attempting to use rowserrcheck with github.com/jackc/pgx/v4, and it didn't seem to be working. I started debugging the code, and I found a solution that seems to work.

github.com/jackc/pgx/v4.Rows is an interface instead of a concrete struct type, so I updated the code to support that as best as I could.

I also had to update the go.mod / go.sum files to get things to work with Go 1.16 code that I'm working on.

EDIT: noImportedDBSQL seemed to be excluding files that needed to be checked. jackc/pgx is rarely imported in the same files that need to call rows.Err().

@leventov
Copy link

@jingyugao could we merge this?

@jingyugao jingyugao merged commit bd4dd44 into jingyugao:master Oct 18, 2021
r.rowsTyp = types.NewPointer(resNamed)
r.skipFile = map[*ast.File]bool{}

for _, f := range funcs {
if r.noImportedDBSQL(f) {
Copy link
Owner

Choose a reason for hiding this comment

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

Why delete? This will cost more time on lint.

Copy link
Author

Choose a reason for hiding this comment

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

I mentioned it in the description of the PR.

for the github.com/jackc/pgx library that is commonly used for PostgreSQL, db/sql usually isn’t imported, so that noImportedDBSQL check was preventing the linter from seeing files with incorrect code.

In a lot of cases in my code, jackc/pgx isn’t even imported directly into files that are using those connections… it is just indirectly imported by accessing a connection pool object that is in another package.

Copy link
Owner

Choose a reason for hiding this comment

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

Can we check if it importgithub.com/jackc/pgx library?


for i := 0; i < res.Len(); i++ {
flag = flag || types.Identical(res.At(i).Type(), r.rowsTyp)
Copy link
Owner

Choose a reason for hiding this comment

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

I think line 93 should have same change. Otherwise for a function return pgx.Rows and it doesn't close the row, the lint will make it will make false positive

@jingyugao
Copy link
Owner

Could you plz add some test case for this change?

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.

3 participants