Skip to content

GH-51228: [Python] Raise instead of crashing on an invalid registry - #51247

Open
1fanwang wants to merge 4 commits into
apache:mainfrom
1fanwang:1fannnw/gh-51228-call-tabular-registry
Open

1fanwang wants to merge 4 commits into
apache:mainfrom
1fanwang:1fannnw/gh-51228-call-tabular-registry

Conversation

@1fanwang

@1fanwang 1fanwang commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Passing an invalid registry to a tabular call or UDF registration can terminate Python. Applications should receive TypeError instead.

Fixes #51228.

What changes are included in this PR?

Validate the registry before reading its native pointer. The shared registration check covers scalar, vector, aggregate, and tabular functions. Default and explicit registries retain their behavior.

Are these changes tested?

Built from source on macOS arm64 with Python 3.12.14. Six invalid calls crashed in separate processes on upstream main, then raised TypeError after the fix. Default and explicit registries still returned the same one-row table.

Raw logs
$ python -c "import pyarrow as pa; import pyarrow.compute as pc; pc.call_tabular_function('', None, 0.0)"
Before:
tabular_call_float: returncode=-10
After:
TypeError: func_registry must be a FunctionRegistry
tabular_call_float: returncode=1

$ python -c "import pyarrow as pa; import pyarrow.compute as pc; pc.register_scalar_function(func=lambda context: None, function_name='example', function_doc={'summary': '', 'description': ''}, in_types={}, out_type=pa.struct([]), func_registry=1)"
Before:
scalar: returncode=-11
After:
TypeError: func_registry must be a FunctionRegistry
scalar: returncode=1

$ python -m pytest pyarrow/tests/test_compute.py pyarrow/tests/test_udf.py pyarrow/tests/test_csv.py::TestThreadedCSVTableRead::test_cancellation -q --tb=short --basetemp=build/pytest-51247
652 passed, 4 skipped, 7 warnings in 3.35s

Are there any user-facing changes?

Invalid registry arguments raise TypeError instead of terminating Python.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copilot AI lite review requested due to automatic review settings September 8, 2026 19:52
@github-actions github-actions Bot added the awaiting review Awaiting review label Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #51228 has been automatically assigned in GitHub to PR creator.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new subprocess-based test should be marked with @pytest.mark.processes so it can be skipped on platforms/configurations where process creation is disabled.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes a crash in the PyArrow compute bindings by validating the optional func_registry argument passed to pyarrow.compute.call_tabular_function() before performing the Cython cast, so invalid types raise a catchable TypeError instead of segfaulting.

Changes:

  • Add a runtime type check for func_registry in call_tabular_function() and raise TypeError on invalid values.
  • Add a regression test that runs the call in a subprocess to assert the failure mode is a Python exception (not a process crash).
File summaries
File Description
python/pyarrow/_compute.pyx Adds func_registry type validation before casting to a native registry pointer.
python/pyarrow/tests/test_compute.py Adds a subprocess-based regression test to ensure invalid registries raise TypeError rather than crashing.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread python/pyarrow/tests/test_compute.py
Copilot AI review requested due to automatic review settings September 8, 2026 22:39
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Sep 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The fix is narrowly scoped, matches the stated user-facing behavior, and is covered by a regression test that would fail under the prior segfaulting implementation.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@AlenkaF AlenkaF left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make sense to also add a check in _register_user_defined_function as every register_* function uses that?

Comment thread python/pyarrow/tests/test_compute.py
Copilot AI review requested due to automatic review settings September 10, 2026 11:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The added regression test should be executed in a subprocess (as described) to remain safe if the segfault regresses and to avoid crashing the test runner.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread python/pyarrow/tests/test_compute.py
@AlenkaF

AlenkaF commented Sep 11, 2026

Copy link
Copy Markdown
Member

Two things left:

Copilot AI review requested due to automatic review settings September 12, 2026 04:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The fix is covered by regression tests and prevents the reported process crash.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #51228 has been automatically assigned in GitHub to PR creator.

@1fanwang

Copy link
Copy Markdown
Contributor Author

Done in 388ac7b.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #51228 has been automatically assigned in GitHub to PR creator.

1 similar comment
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #51228 has been automatically assigned in GitHub to PR creator.

Copilot AI review requested due to automatic review settings September 22, 2026 02:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The validation consistently addresses the reported crash path and is covered by regression tests.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 24, 2026 06:16
@1fanwang
1fanwang force-pushed the 1fannnw/gh-51228-call-tabular-registry branch from 10eed8b to 80261c3 Compare September 24, 2026 06:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The crash fix and regression coverage are complete, with no unresolved review issues.

Review effort: Lite
Findings: None

Validate call_tabular_function registry inputs before casting them to the native FunctionRegistry pointer.

Signed-off-by: Stefan Wang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
The test spawns a subprocess, which Emscripten does not support. Without
the marker the test runs there anyway and fails.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
The subprocess wrapper guarded against the crash this change removes, so
the in-process form reads better now.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang force-pushed the 1fannnw/gh-51228-call-tabular-registry branch from 80261c3 to 000992c Compare September 25, 2026 20:51
Copilot AI review requested due to automatic review settings September 25, 2026 20:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

Invalid registries are validated and regression coverage is included.

Review effort: Lite
Findings: None

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #51228 has been automatically assigned in GitHub to PR creator.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] call_tabular_function() segfaults for some wrong typed func_registry values

3 participants