Skip to content

Revert "Statically link JSON extension in pybind CI"#20

Open
adsharma wants to merge 2 commits into
mainfrom
revert_static_ext
Open

Revert "Statically link JSON extension in pybind CI"#20
adsharma wants to merge 2 commits into
mainfrom
revert_static_ext

Conversation

@adsharma
Copy link
Copy Markdown
Contributor

@adsharma adsharma commented May 28, 2026

Related: LadybugDB/ladybug#462

Summary

This PR keeps the JSON extension loaded dynamically in Python CI and fixes a C API cleanup issue found while testing that path.

Why this failed

The JSON roundtrip test was segfaulting on CI only after earlier C API scan tests had run. The JSON setup query itself has no parameters, so the crash was unlikely to be caused by the JSON parameter normalization path. The suspicious shared state was the C API Arrow scan adapter added for Python object scans.

For C API scans, the Python wrapper rewrites a parameterized PyArrow/pandas/polars scan into a temporary Arrow-backed table. Before this change, those temp tables were dropped only after successful query execution. If the rewritten query failed after the temp table was created, cleanup was skipped and Arrow C Data Interface objects stayed registered in the native Arrow table registry. That leaked native/PyArrow-backed state could corrupt later unrelated tests, which explains why a later INSTALL json; LOAD json; ... query was where the process finally crashed.

Why the fix works

Connection.execute() now records the C API scan tables that were created during rewrite and drops them in a finally block. That makes cleanup happen on both success and failure, while preserving the original query error if cleanup also has trouble during exception unwinding.

The added regression test forces this exact failure mode: create a parameterized PyArrow COPY scan, make the query fail, and assert that _capi_scan_tables is empty afterward. With the cleanup in place, the focused C API JSON smoke test and the broader CI ordering both pass.

Validation

  • uv run ruff check src_py/connection.py test/test_scan_pyarrow.py
  • LBUG_PYTHON_BACKEND=capi uv run pytest test/test_scan_pyarrow.py::test_pyarrow_copy_from_failed_query_cleans_capi_scan_table test/test_scan_pyarrow.py::test_pyarrow_copy_from_parameterized_df test/test_json.py::test_to_json_string_param_roundtrip -q
  • LBUG_PYTHON_BACKEND=capi uv run pytest test/test_issue.py test/test_json.py::test_to_json_string_param_roundtrip -q

@adsharma adsharma force-pushed the revert_static_ext branch 5 times, most recently from 14f60fd to fe12da7 Compare May 28, 2026 18:37
@adsharma adsharma force-pushed the revert_static_ext branch from 06c518e to 608f5f0 Compare May 28, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant