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

Fix for BatchReadOnlyTransaction check #48

Closed
wants to merge 1 commit into from
Closed

Conversation

sters
Copy link

@sters sters commented Sep 5, 2022

I have a weird case of using BatchReadOnlyTransaction, please check f7 testcase.

I guess the reason is BatchReadOnlyTransaction.Close and ReadOnlyTransaction.Close are different.
https://github.com/googleapis/google-cloud-go/blob/main/spanner/batch.go#L246-L251

So, I added BatchReadOnlyTransaction.Close to close method list.
(I don't have confidence on my changes.)

@sters sters marked this pull request as ready for review September 5, 2022 08:31
@sters
Copy link
Author

sters commented Sep 5, 2022

@tenntenn @sinmetal
(I'm not sure the actual owner. I refered to the latest PR #45)

Please review this PR.


for {
_, err := iter.Next()
if err == iterator.Done {
Copy link
Member

Choose a reason for hiding this comment

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

実際に実行するわけじゃないのだろうけど、err != nilだったら、一生このループ抜けられないのか・・・wって思ってしまったw

Copy link
Author

Choose a reason for hiding this comment

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

確かに、、 err != nil だけにしました。

Copy link
Member

@tenntenn tenntenn left a comment

Choose a reason for hiding this comment

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

I leave comments.

@@ -73,3 +73,22 @@ func f6(ctx context.Context, client *spanner.Client) error {
}
return nil
}

func f7(ctx context.Context, client *spanner.Client) error {
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a test case which does not call Close method with a // want comment.

Copy link
Author

Choose a reason for hiding this comment

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

f5 is that the testcase.

func f5(ctx context.Context, client *spanner.Client) {
tx, _ := client.BatchReadOnlyTransaction(ctx, spanner.StrongRead()) // want "transaction must be closed"
_ = tx
}

@@ -59,7 +68,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
// skip this
continue
}
instrs := analysisutil.NotCalledIn(f, txTyp, methods...)
instrs := analysisutil.NotCalledIn(f, txTypeRo, methods...)
Copy link
Member

Choose a reason for hiding this comment

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

Because the second argument of NotCalledIn is a receiver of the methods, it cannot find txTypeBatch's methods.

I think you should call NotCalledIn two times for txTypRo and txTypeBatch and merge theses return values into instrs.

Copy link
Author

@sters sters Sep 25, 2022

Choose a reason for hiding this comment

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

When I use this:

instrs := append(
	analysisutil.NotCalledIn(f, txTypeRo, methods...),
	analysisutil.NotCalledIn(f, txTypeBatch, methods...)...,
)
for _, instr := range instrs {
...

The test says:

/my/go/path/root/sters/zagane/passes/unclosetx/analysistest.go:446: a/a.go:55:42: unexpected diagnostic: transaction must be closed

it points to this test case:

image

I have no idea to solve this test failure. 🤔

@sters
Copy link
Author

sters commented May 14, 2024

Let me close this PR. Feel free to pick my commit. 🙏

@sters sters closed this May 14, 2024
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.

None yet

3 participants