Skip to content

Conversation

@evangelisilva
Copy link

Which issue does this PR close?

Rationale for this change

This PR fixes a potential panic in ListingTableFactory::create when the provided Session instance is not a SessionState.

Previously, the code used .unwrap() on downcast_ref::<SessionState>(). If a custom Session implementation was used (which is allowed by the trait), this would cause a crash. This change replaces .unwrap() with ok_or_else, returning a proper DataFusionError::Internal instead.

What changes are included in this PR?

  • Replaced .unwrap() with ok_or_else in ListingTableFactory::create to safely handle session downcasting.
  • Added a regression test test_create_with_invalid_session in datafusion/core/src/datasource/listing_table_factory.rs that uses a MockSession to verify the error is returned instead of panicking.

Are these changes tested?

Yes.

  • Added new unit test test_create_with_invalid_session.
  • Ran cargo test -p datafusion --lib datasource::listing_table_factory::tests::test_create_with_invalid_session and it passed.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the core Core DataFusion crate label Feb 3, 2026
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @evangelisilva -- this looks good to me



#[tokio::test]
async fn test_create_with_invalid_session() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is probably overkill, but it isn't a terrible thing to have coverage

@alamb
Copy link
Contributor

alamb commented Feb 3, 2026

I ran cargo fmt to resolve the CI run and merged up from main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential panic due to unchecked downcast in ListingTableFactory::create

2 participants