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
database/sql: Use sql.Tx.ctx by default in sql.Tx methods instead of context.Background() #20098
Comments
Hi @bgaifullin, the subject of this issue doesn't have the correct format. It should be something like: |
Hi @matipan, I have updated title. thank you. |
@bgaifullin This suggestion has merit. However I would resist this suggestion for two reasons:
All that being said, in this case all queries in a Tx live in the span of the Tx. It does have some merit in this case. I'm going to hold off closing it for now, but it is unlikely to be accepted. Thanking. |
@kardianos, thank you. My point was that the sql.Tx was created with context, and methods Commit and Rollback use this context. But other methods do not use and I as a user have to pass the same context to methods Query, Exec. IMHO it is unlogical. |
@bgaifullin I understand your point. It has merit. Do you have a response for my two points? |
|
CL https://golang.org/cl/44956 mentions this issue. |
I would love to see a proposal for adding CommitContext and RollbackContext. They can be added in a backwards compatible way, just like the other context methods. |
@bgaifullin If there is a go2, there wouldn't be any query variants without a context argument. I want to strongly encurage all uses of Query and Exec methods to include a context directly in their arguments. This is probably too late for a go1.9 change. @rsc My sense for some of these topics (context, go2, release cycle) have been wrong a number of times in the past. Would you be willing to weigh in on this? |
@kardianos I got your point, thank you for feedback. |
What version of Go are you using (
go version
)?go version go1.8 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
I found that method of sql.Tx uses context.Background by default even sql.Tx has ctx property.
I expect that creating sql.Tx via method sql.DB.BeginTx, the sql.Tx will use the same context for all methods event another is not specified directly through special methods, which accept context argument.
for example:
The text was updated successfully, but these errors were encountered: