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

Improve transaction handling #538

Merged
merged 5 commits into from
Feb 13, 2025

Conversation

fabianfett
Copy link
Collaborator

@fabianfett fabianfett commented Feb 11, 2025

Improve transaction handling a bit further:

  • Add an explicit PostgresTransactionError
  • Populate the PostgresTransactionError if needed
  • Add withTransaction function to PostgresConnection as well

cc @thoven87 @FranzBusch

Follow up to #519.

@fabianfett fabianfett requested a review from gwynne as a code owner February 11, 2025 13:01
@fabianfett fabianfett added the semver-minor Adds new public API. label Feb 11, 2025
logger: Logger,
file: String = #file,
line: Int = #line,
_ process: (PostgresConnection) async throws -> Result
Copy link
Contributor

Choose a reason for hiding this comment

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

Just realized for Swift 6 you probably want to have a variant that adds a isolation: isolated (any Actor)? = #isolation as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's why I wanted a review from you :)

@fabianfett
Copy link
Collaborator Author

@FranzBusch please rereview.

logger: Logger,
file: String = #file,
line: Int = #line,
isolation: isolated (any Actor)? = #isolation,
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be guarded to only apply in Swift 6, need a variant that doesn't have it for Swift 5. Same in PostgresClient.

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 0% with 60 lines in your changes missing coverage. Please review.

Project coverage is 61.38%. Comparing base (712740b) to head (938bedf).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...es/PostgresNIO/Connection/PostgresConnection.swift 0.00% 48 Missing ⚠️
Sources/PostgresNIO/Pool/PostgresClient.swift 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #538      +/-   ##
==========================================
- Coverage   61.67%   61.38%   -0.30%     
==========================================
  Files         125      125              
  Lines       10099    10149      +50     
==========================================
+ Hits         6229     6230       +1     
- Misses       3870     3919      +49     
Files with missing lines Coverage Δ
Sources/PostgresNIO/Pool/PostgresClient.swift 0.00% <0.00%> (ø)
...es/PostgresNIO/Connection/PostgresConnection.swift 38.44% <0.00%> (-4.32%) ⬇️

... and 1 file with indirect coverage changes

public var rollbackError: Error?

/// The error thrown while commiting the transaction.
public var commitError: Error?
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to have a public init for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not for now I think.

@fabianfett fabianfett force-pushed the ff-improved-transaction branch from 1c8e524 to 6b885c6 Compare February 13, 2025 09:34
@fabianfett
Copy link
Collaborator Author

2 breaking changes detected in PostgresNIO:
  💔 API breakage: func PostgresClient.withTransaction(_:) has parameter 0 type change from (PostgresNIO.PostgresConnection) async throws -> Result to Logging.Logger
  💔 API breakage: func PostgresClient.withTransaction(_:) has been renamed to func withTransaction(logger:file:line:isolation:_:)

Those are fine as the withTransaction API hasn't been released yet.

@fabianfett fabianfett merged commit 5d817be into vapor:main Feb 13, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants