1fanwang opened a new pull request, #51294:
URL: https://github.com/apache/arrow/pull/51294

   ### Rationale for this change
   
   `pyarrow.dataset.get_partition_keys(None)` kills the interpreter instead of 
raising.
   
   The parameter is typed `Expression` but is not declared `not None`, so 
Cython passes
   the null straight through and the body dereferences it. The process dies 
with a bus
   error and no Python traceback. Code that pulls a partition expression off a 
fragment
   and forwards it without a null check loses the interpreter, and the crash 
carries
   nothing pointing back at the call.
   
   On the released 25.0.1 build:
   
   ```console
   $ python -c "import pyarrow.dataset as ds; ds.get_partition_keys(None)"
   Bus error: 10
   $ echo $?
   138
   ```
   
   ### What changes are included in this PR?
   
   Declare the parameter `not None` so Cython rejects the null at the call 
boundary, and
   add the case to `test_partition_keys`.
   
   Required typed parameters elsewhere in this module already carry that 
annotation, so
   this closes a gap rather than introducing a convention.
   
   ### Are these changes tested?
   
   Yes, `test_partition_keys` gains a `None` case.
   
   Rebuilt 25.0.1 with only this change, against the matching Arrow C++ 25.0.1, 
so the
   before and after differ by the annotation alone:
   
   ```console
   $ python -c "
   import pyarrow.dataset as ds
   ds.get_partition_keys(None)"
   TypeError: Argument 'partition_expression' has incorrect type (expected 
pyarrow._compute.Expression, got NoneType)
   ```
   
   Valid input is unaffected:
   
   ```console
   $ python -c "
   import pyarrow.dataset as ds
   e = (ds.field('a') == 1) & (ds.field('b') == 'x')
   print(ds.get_partition_keys(e))"
   {'a': 1, 'b': 'x'}
   ```
   
   ### Are there any user-facing changes?
   
   Passing `None` raises `TypeError` instead of terminating the process. No 
valid call
   changes behavior.
   
   This PR removes an interpreter crash reachable from a public function.
   
   Closes #51293.
   


-- 
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]

Reply via email to