Skip to content

Commit f4bf367

Browse files
hatemosphereclaude
andcommitted
fix(postgres): expose in_transaction() as public API
Change `pub(crate) fn in_transaction` to `pub fn in_transaction` on `PgConnection` to allow checking PostgreSQL's protocol-level transaction status from outside the crate. This is needed to implement an efficient `after_release` pool hook that only issues ROLLBACK when a connection actually has an open transaction, working around the cancel-safety bug in `PgTransactionManager::begin()` (see launchbadge/sqlx#2805). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4827e7c commit f4bf367

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

Cargo.toml

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
name = "sqlx-postgres"
33
documentation = "https://docs.rs/sqlx"
44
description = "PostgreSQL driver implementation for SQLx. Not for direct use; see the `sqlx` crate for details."
5-
version.workspace = true
6-
license.workspace = true
7-
edition.workspace = true
8-
authors.workspace = true
9-
repository.workspace = true
5+
version = "0.8.6"
6+
license = "MIT OR Apache-2.0"
7+
edition = "2021"
8+
authors = [
9+
"Ryan Leckey <leckey.ryan@gmail.com>",
10+
"Austin Bonander <austin.bonander@gmail.com>",
11+
"Chloe Ross <orangesnowfox@gmail.com>",
12+
]
13+
repository = "https://github.com/launchbadge/sqlx"
1014
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1115

1216
[features]
@@ -40,23 +44,23 @@ md-5 = { version = "0.10.0", default-features = false }
4044
rand = { version = "0.8.4", default-features = false, features = ["std", "std_rng"] }
4145
sha2 = { version = "0.10.0", default-features = false }
4246

43-
# Type Integrations (versions inherited from `[workspace.dependencies]`)
44-
bigdecimal = { workspace = true, optional = true }
45-
bit-vec = { workspace = true, optional = true }
46-
chrono = { workspace = true, optional = true }
47-
ipnet = { workspace = true, optional = true }
48-
ipnetwork = { workspace = true, optional = true }
49-
mac_address = { workspace = true, optional = true }
50-
rust_decimal = { workspace = true, optional = true }
51-
time = { workspace = true, optional = true }
52-
uuid = { workspace = true, optional = true }
47+
# Type Integrations
48+
bigdecimal = { version = "0.4.0", optional = true }
49+
bit-vec = { version = "0.6.3", optional = true }
50+
chrono = { version = "0.4.34", default-features = false, features = ["std", "clock"], optional = true }
51+
ipnet = { version = "2.3.0", optional = true }
52+
ipnetwork = { version = "0.20.0", optional = true }
53+
mac_address = { version = "1.1.5", optional = true }
54+
rust_decimal = { version = "1.26.1", default-features = false, features = ["std"], optional = true }
55+
time = { version = "0.3.36", features = ["formatting", "parsing", "macros"], optional = true }
56+
uuid = { version = "1.1.2", optional = true }
5357

5458
# Misc
5559
atoi = "2.0"
5660
base64 = { version = "0.22.0", default-features = false, features = ["std"] }
5761
bitflags = { version = "2", default-features = false }
5862
byteorder = { version = "1.4.3", default-features = false, features = ["std"] }
59-
dotenvy = { workspace = true }
63+
dotenvy = { version = "0.15.7", default-features = false }
6064
hex = "0.4.3"
6165
home = "0.5.5"
6266
itoa = "1.0.1"
@@ -74,16 +78,15 @@ serde = { version = "1.0.144", features = ["derive"] }
7478
serde_json = { version = "1.0.85", features = ["raw_value"] }
7579

7680
[dependencies.sqlx-core]
77-
workspace = true
81+
version = "=0.8.6"
7882
# We use JSON in the driver implementation itself so there's no reason not to enable it here.
7983
features = ["json"]
8084

81-
[dev-dependencies.sqlx]
82-
workspace = true
83-
features = ["postgres", "derive"]
84-
8585
[target.'cfg(target_os = "windows")'.dependencies]
8686
etcetera = "0.8.0"
8787

88-
[lints]
89-
workspace = true
88+
[lints.clippy]
89+
cast_possible_truncation = 'deny'
90+
cast_possible_wrap = 'deny'
91+
cast_sign_loss = 'deny'
92+
disallowed_methods = 'deny'

src/connection/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ impl PgConnection {
131131
Ok(())
132132
}
133133

134-
pub(crate) fn in_transaction(&self) -> bool {
134+
// PATCHED: changed from pub(crate) to pub to allow checking transaction status in after_release hook
135+
pub fn in_transaction(&self) -> bool {
135136
match self.inner.transaction_status {
136137
TransactionStatus::Transaction => true,
137138
TransactionStatus::Error | TransactionStatus::Idle => false,

0 commit comments

Comments
 (0)