evangelisilva opened a new pull request, #20139:
URL: https://github.com/apache/datafusion/pull/20139

   ## Which issue does this PR close?
   
   - Closes #20113.
   
   ## Rationale for this change
   
   This PR fixes a potential panic in `ListingTableFactory::create` when the 
provided 
[Session](cci:2://file:///Users/evangelisilva/.gemini/antigravity/scratch/datafusion/datafusion/session/src/session.rs:71:0-140:1)
 instance is not a `SessionState`.
   
   Previously, the code used `.unwrap()` on `downcast_ref::<SessionState>()`. 
If a custom 
[Session](cci:2://file:///Users/evangelisilva/.gemini/antigravity/scratch/datafusion/datafusion/session/src/session.rs:71:0-140:1)
 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](cci:1://file:///Users/evangelisilva/.gemini/antigravity/scratch/datafusion/datafusion/core/src/datasource/listing_table_factory.rs:554:4-638:5)
 in 
[datafusion/core/src/datasource/listing_table_factory.rs](cci:7://file:///Users/evangelisilva/.gemini/antigravity/scratch/datafusion/datafusion/core/src/datasource/listing_table_factory.rs:0:0-0:0)
 that uses a 
[MockSession](cci:2://file:///Users/evangelisilva/.gemini/antigravity/scratch/datafusion/datafusion/core/src/datasource/listing_table_factory.rs:570:8-570:27)
 to verify the error is returned instead of panicking.
   
   ## Are these changes tested?
   
   Yes.
   - Added new unit test 
[test_create_with_invalid_session](cci:1://file:///Users/evangelisilva/.gemini/antigravity/scratch/datafusion/datafusion/core/src/datasource/listing_table_factory.rs:554:4-638:5).
   - 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to