Skip to content

with_session_state silently falls back when Session isn't SessionState #4081

@ethan-tyler

Description

@ethan-tyler

What happened?

Builders like OptimizeBuilder, MergeBuilder, UpdateBuilder accept Arc via with_session_state(...), but internally require a concrete SessionState. When the downcast fails, they silently fall back to an internal default:

session.as_any().downcast_ref::<SessionState>()
    .cloned()
    .unwrap_or_else(|| create_internal_session_state(...))

Relevant paths:

  • crates/core/src/operations/optimize.rs
  • crates/core/src/operations/merge/mod.rs
  • crates/core/src/operations/update.rs

The operation "works", but caller-provided config/runtime/registrations get silently ignored.

Expected behavior

Either accept SessionState directly, error when downcast fails, or at minimum log/document that fallback happened.

Operating System

All (API-level behavior)

Binding

Rust

Bindings Version

Observed on main / DF52 upgrade work (DataFusion 52).

Steps to reproduce

  1. Create a session with custom config (runtime env, target partitions, UDF registrations, etc.)
  2. Pass it to OptimizeBuilder::with_session_state(...) as Arc where concrete type isn't SessionState
  3. Operation runs with internal defaults instead of caller's session - no warning

Relevant logs

N/A (the problem is the absence of any warning/error when fallback happens)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions