Skip to content

add support for scoped lifetimes in transaction callbacks #2381

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

Closed
wants to merge 3 commits into from

Conversation

tlowerison
Copy link

Hi there! This revision changes the callback parameter F in the Connection::transaction method to allow F to have a scoped lifetime associated with it that is shorter than 'static but longer than the hrtb attached to the callback's connection pararmeter. I'm coming from mostly using diesel so I'm not sure if there's a demand for this feature in sqlx but it seems useful. I merged a similar change in the diesel-async project here.

As mentioned in that revision, the main downside of introducing this change would be the breaking change on application code calling Connection::transaction if they pass a callback that is boxed using FutureExt::boxed because now they would need to use ScopedFutureExt::scope_boxed or Box::pinned.

@abonander
Copy link
Collaborator

@tlowerison sorry for the delay, can you add a test or a doc example showing this working as expected?

@tlowerison
Copy link
Author

@abonander sure thing, just updated the postgres transaction example to work with 0.7.0-alpha.3 and give an example of using references in transaction callbacks (note how the boxed future returned from the callback uses async instead of async move)

@tlowerison
Copy link
Author

there's an updated doc example on the transaction function here which shows the same idea as well

@abonander
Copy link
Collaborator

abonander commented Jul 14, 2023

I apologize but I never had time to look at this in-depth.

I'm very wary of merging a dependency on a bespoke crate for one function, especially when both crate and PR have the same author. I have no doubt your intentions are benign, but it just screams "potential supply chain attack" to me.

I'd rather just get rid of this function entirely; I've never liked it because of the various problems it has. I might replace it with a macro because I do see the utility in having something like this, which would also avoid needing a boxed return type.

@abonander abonander closed this Jul 14, 2023
@tlowerison
Copy link
Author

Totally understandable, and I agree a non-boxed solution would be much preferable. Thanks for the taking time to write out a detailed response.

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.

2 participants