Skip to content

Commit 67715c6

Browse files
timsaucerclaude
andcommitted
docs: clarify py_session_from_session downcast is defensive
The doc comment implied a foreign FFI session was a real input. No current path reaches a pure-Python UDTF with a non-SessionState session: the SQL planner and __call__ both hand a SessionState, and a ForeignSession would only arrive via FFI-export of the UDTF, which datafusion-python does not do. Reword to state the guard is defensive and rewrap the error string. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b57325f commit 67715c6

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

crates/core/src/udtf.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,26 @@ impl PyTableFunction {
129129
/// rather than an owned context; we downcast it to the canonical
130130
/// :class:`SessionState` impl and rebuild a :class:`SessionContext`
131131
/// (sharing the same registries via the Arc-heavy interior of
132-
/// :class:`SessionState`). Returns an error if the trait object is a
133-
/// non-:class:`SessionState` implementation (e.g. a foreign FFI
134-
/// session) — those are not exposed to Python today.
132+
/// :class:`SessionState`).
133+
///
134+
/// The downcast is defensive. Every path that reaches a pure-Python
135+
/// UDTF today hands us a `SessionState`: the SQL planner builds the
136+
/// args from its own `SessionState`, and `PyTableFunction::__call__`
137+
/// uses the global context's state. A non-`SessionState` session
138+
/// (e.g. a `ForeignSession`) would only arrive if this UDTF were
139+
/// exported across the FFI boundary to a foreign-library consumer,
140+
/// which datafusion-python does not do. Should that change, this
141+
/// returns an error rather than silently misbehaving.
135142
fn py_session_from_session(session: &dyn Session) -> DataFusionResult<PySessionContext> {
136143
let state = session
137144
.as_any()
138145
.downcast_ref::<SessionState>()
139146
.ok_or_else(|| {
140147
DataFusionError::Execution(
141-
"Cannot expose this UDTF's calling session to Python: \
142-
the session is not a SessionState. Drop the `session` \
143-
keyword from the callback signature to fall back to the \
144-
expression-only call form."
148+
"Cannot expose this UDTF's calling session to Python: the \
149+
session is not a SessionState. Drop the `session` keyword \
150+
from the callback signature to fall back to the \
151+
expression-only call form."
145152
.to_string(),
146153
)
147154
})?;

0 commit comments

Comments
 (0)