From a591fc84a4443f890d5a434c35ef2be408442022 Mon Sep 17 00:00:00 2001 From: "kistz (Kilian Strunz)" Date: Mon, 15 Jun 2026 14:31:34 +0200 Subject: [PATCH 1/4] fix the wrong behaviour --- crates/bindings/src/http.rs | 6 +++--- crates/bindings/src/lib.rs | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/crates/bindings/src/http.rs b/crates/bindings/src/http.rs index ec476bba46e..b17a806a131 100644 --- a/crates/bindings/src/http.rs +++ b/crates/bindings/src/http.rs @@ -127,18 +127,18 @@ impl HandlerContext { } /// Read the current module's [`Identity`]. - pub fn identity(&self) -> Identity { + pub fn database_identity(&self) -> Identity { Identity::from_byte_array(spacetimedb_bindings_sys::identity()) } /// Acquire a mutable transaction and execute `body` with read-write access. pub fn with_tx(&mut self, body: impl Fn(&TxContext) -> T) -> T { - with_tx(body) + with_tx(body, Identity::ZERO, None) } /// Acquire a mutable transaction and execute `body` with read-write access. pub fn try_with_tx(&mut self, body: impl Fn(&TxContext) -> Result) -> Result { - try_with_tx(body) + try_with_tx(body, Identity::ZERO, None) } /// Create a new random [`Uuid`] `v4` using the built-in RNG. diff --git a/crates/bindings/src/lib.rs b/crates/bindings/src/lib.rs index 62b78e14be4..d132cefd80a 100644 --- a/crates/bindings/src/lib.rs +++ b/crates/bindings/src/lib.rs @@ -1180,7 +1180,11 @@ impl Deref for TxContext { } } -fn try_with_tx(body: impl Fn(&TxContext) -> Result) -> Result { +fn try_with_tx( + body: impl Fn(&TxContext) -> Result, + identity: Identity, + connection_id: Option, +) -> Result { let abort = || { crate::sys::procedure::procedure_abort_mut_tx() .expect("should have a pending mutable anon tx as `procedure_start_mut_tx` preceded") @@ -1192,7 +1196,7 @@ fn try_with_tx(body: impl Fn(&TxContext) -> Result) -> Result let timestamp = Timestamp::from_micros_since_unix_epoch(timestamp); // Use the internal auth context (no external caller identity). - let tx = ReducerContext::new(crate::Local {}, Identity::ZERO, None, timestamp); + let tx = ReducerContext::new(crate::Local {}, identity, connection_id, timestamp); let tx = TxContext(tx); struct DoOnDrop(F); @@ -1225,9 +1229,9 @@ fn try_with_tx(body: impl Fn(&TxContext) -> Result) -> Result res } -fn with_tx(body: impl Fn(&TxContext) -> T) -> T { +fn with_tx(body: impl Fn(&TxContext) -> T, identity: Identity, connection_id: Option) -> T { use core::convert::Infallible; - match try_with_tx::(|tx| Ok(body(tx))) { + match try_with_tx::(|tx| Ok(body(tx)), identity, connection_id) { Ok(v) => v, Err(e) => match e {}, } @@ -1293,7 +1297,13 @@ impl ProcedureContext { } /// Read the current module's [`Identity`]. + #[deprecated(note = "Use `ProcedureContext::database_identity` instead.")] pub fn identity(&self) -> Identity { + self.database_identity() + } + + /// Read the current module's [`Identity`]. + pub fn database_identity(&self) -> Identity { // Hypothetically, we *could* read the module identity out of the system tables. // However, this would be: // - Onerous, because we have no tooling to inspect the system tables from module code. @@ -1359,7 +1369,7 @@ impl ProcedureContext { /// callers should avoid writing to any captured mutable state within `body`, /// This includes interior mutability through types like [`std::cell::Cell`]. pub fn with_tx(&mut self, body: impl Fn(&TxContext) -> T) -> T { - with_tx(body) + with_tx(body, self.sender(), self.connection_id()) } /// Acquire a mutable transaction @@ -1392,7 +1402,7 @@ impl ProcedureContext { /// callers should avoid writing to any captured mutable state within `body`, /// This includes interior mutability through types like [`std::cell::Cell`]. pub fn try_with_tx(&mut self, body: impl Fn(&TxContext) -> Result) -> Result { - try_with_tx(body) + try_with_tx(body, self.sender(), self.connection_id()) } /// Create a new random [`Uuid`] `v4` using the built-in RNG. From 8c5d8c2572a718d82be5d7d971952d391d938553 Mon Sep 17 00:00:00 2001 From: "kistz (Kilian Strunz)" Date: Mon, 15 Jun 2026 14:37:29 +0200 Subject: [PATCH 2/4] adjust docs --- crates/bindings/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bindings/src/lib.rs b/crates/bindings/src/lib.rs index d132cefd80a..0d375719829 100644 --- a/crates/bindings/src/lib.rs +++ b/crates/bindings/src/lib.rs @@ -1180,6 +1180,9 @@ impl Deref for TxContext { } } +/// We need to passthrough identity and connection_id because procedures can be invoked by users. +/// For [HttpContext] this is always anonymous ([Identity::ZERO]). +/// Construct the inner [ReducerContext] with the appropriate caller information. fn try_with_tx( body: impl Fn(&TxContext) -> Result, identity: Identity, @@ -1195,7 +1198,6 @@ fn try_with_tx( .expect("holding `&mut HandlerContext`, so should not be in a tx already; called manually elsewhere?"); let timestamp = Timestamp::from_micros_since_unix_epoch(timestamp); - // Use the internal auth context (no external caller identity). let tx = ReducerContext::new(crate::Local {}, identity, connection_id, timestamp); let tx = TxContext(tx); From d38d43a99776e6f3dcd60b94453afcc460f2ee74 Mon Sep 17 00:00:00 2001 From: "kistz (Kilian Strunz)" Date: Tue, 16 Jun 2026 21:14:34 +0200 Subject: [PATCH 3/4] deprecate instead of remove --- crates/bindings/src/http.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/bindings/src/http.rs b/crates/bindings/src/http.rs index b17a806a131..0fb8a63d53b 100644 --- a/crates/bindings/src/http.rs +++ b/crates/bindings/src/http.rs @@ -126,6 +126,12 @@ impl HandlerContext { } } + /// Read the current module's [`Identity`]. + #[deprecated(note = "Use `HandlerContext::database_identity` instead.")] + pub fn identity(&self) -> Identity { + self.database_identity() + } + /// Read the current module's [`Identity`]. pub fn database_identity(&self) -> Identity { Identity::from_byte_array(spacetimedb_bindings_sys::identity()) From 1e69d35de36ed57bb1a4bed0264f7efaab1bb8dd Mon Sep 17 00:00:00 2001 From: joshua-spacetime Date: Tue, 16 Jun 2026 13:53:07 -0700 Subject: [PATCH 4/4] Fix procedure identity deprecation lints --- modules/module-test/src/lib.rs | 2 +- modules/sdk-test-procedure/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/module-test/src/lib.rs b/modules/module-test/src/lib.rs index 56e6b288e2d..3cf7b75d099 100644 --- a/modules/module-test/src/lib.rs +++ b/modules/module-test/src/lib.rs @@ -543,7 +543,7 @@ fn with_tx(ctx: &mut ProcedureContext) { /// This is a silly thing to do, but an effective test of the procedure HTTP API. #[spacetimedb::procedure] fn get_my_schema_via_http(ctx: &mut ProcedureContext) -> String { - let module_identity = ctx.identity(); + let module_identity = ctx.database_identity(); match ctx.http.get(format!( "http://localhost:3000/v1/database/{module_identity}/schema?version=9" )) { diff --git a/modules/sdk-test-procedure/src/lib.rs b/modules/sdk-test-procedure/src/lib.rs index 95ae9b523b1..930cef6d79b 100644 --- a/modules/sdk-test-procedure/src/lib.rs +++ b/modules/sdk-test-procedure/src/lib.rs @@ -42,7 +42,7 @@ fn will_panic(_ctx: &mut ProcedureContext) { #[procedure] fn read_my_schema(ctx: &mut ProcedureContext) -> String { - let module_identity = ctx.identity(); + let module_identity = ctx.database_identity(); match ctx.http.get(format!( "http://localhost:3000/v1/database/{module_identity}/schema?version=9" )) {