From 792c9973e2d5521c3ffdca9a026f8fd672d222a1 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 16 Jul 2026 15:25:34 +0000 Subject: [PATCH] Accept None for LoggingContext.tag again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The port narrowed `tag` from an untyped Python attribute to a str-only Rust String field, so `context.tag = None` — accepted silently before, and the value the sentinel's `tag` reports — started raising TypeError. Keep the field Optional at runtime (still initialised to "" and typed as str in the stub, matching how all in-tree code treats it). Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01JFbRtswu7rsHrttJFauUUb --- rust/src/logging/context.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rust/src/logging/context.rs b/rust/src/logging/context.rs index cbfcc7fa20..2cded8589b 100644 --- a/rust/src/logging/context.rs +++ b/rust/src/logging/context.rs @@ -449,9 +449,12 @@ pub struct LoggingContext { /// path does no per-switch Python allocation; nothing outside this module /// reads it. usage_start: Option<(f64, f64)>, - /// A short human-readable tag (e.g. the sync type); always a `str`. + /// A short human-readable tag (e.g. the sync type). Initialised to `""` and + /// treated as a `str` by everything in-tree, but kept `Option` so assigning + /// `None` (which the old untyped Python attribute accepted, and which the + /// sentinel's `tag` reports) keeps working rather than raising `TypeError`. #[pyo3(get, set)] - tag: String, + tag: Option, /// The resources used by this context so far. Exposed to Python as /// `_resource_usage` (see the getter below); mutated in place. resource_usage: Py, @@ -489,7 +492,7 @@ impl LoggingContext { main_thread: 0, finished: false, usage_start: None, - tag: String::new(), + tag: Some(String::new()), resource_usage: Py::new(py, ContextResourceUsage::default())?, previous_context: None, parent_context: None, @@ -520,7 +523,7 @@ impl LoggingContext { self.server_name = server_name.unbind(); self.main_thread = get_thread_id(py)?; self.request = None; - self.tag = String::new(); + self.tag = Some(String::new()); self.scope = None; // keep track of whether we have hit the __exit__ block for this context