You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following example reproduces an issue with PyO3, DuckDB, and pyarrow on Windows. The issue is related to the import order of a custom PyO3 module with bundled duckdb (pyo3_duckdb_pyarrow) and the pyarrow module.
Tne problem only occurs on Windows. The code works on Linux.
thread '<unnamed>' panicked at C:\Users\ContainerAdministrator\.cargo\registry\src\index.crates.io-6f17d22bba15001f\duckdb-1.1.1\src\config.rs:127:13:
assertion `left == right` failed
left: 1
right: 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
File "C:\app\test.py", line 4, in<module>pyo3_duckdb_pyarrow.run()
pyo3_runtime.PanicException: assertion `left == right` failed
left: 1
right: 0
The command'cmd /S /C .venv\Scripts\activate.bat && python test.py' returned a non-zero code: 1
Your operating system and version
Windows Container (mcr.microsoft.com/windows/servercore:ltsc2022)
Your Python version (python --version)
3.12.8
Your Rust version (rustc --version)
1.83.0
Your PyO3 version
0.23.4
How did you install python? Did you use a virtualenv?
Used venv, see installation details in the Dockerfile
Additional Info
Detailed Issue description
The issue is related to the import order of pyo3_duckdb_pyarrow module and pyarrow. If the pyarrow module is imported before pyo3_duckdb_pyarrow, the following error occurs on the run method of the pyo3_duckdb_pyarrow module:
thread '<unnamed>' panicked at C:\Users\ContainerAdministrator\.cargo\registry\src\index.crates.io-6f17d22bba15001f\duckdb-1.1.1\src\config.rs:127:13:
assertion `left == right` failed
left: 1
right: 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
File "C:\app\test.py", line 4, in <module>
pyo3_duckdb_pyarrow.run()
pyo3_runtime.PanicException: assertion `left == right` failed
left: 1
right: 0
The command 'cmd /S /C .venv\Scripts\activate.bat && python test.py' returned a non-zero code: 1
The assert_eq!(state, ffi::DuckDBSuccess); lines fails because let state = unsafe { ffi::duckdb_create_config(&mut config) }; returns ffi::DuckDBError.
According to the documentation of (see here) this only can fail due to malloc issues: ... This will always succeed unless there is a malloc failure. ...
use pyo3::pymodule;#[pymodule]mod pyo3_duckdb_pyarrow {use pyo3::pyfunction;use duckdb::DuckdbConnectionManager;#[pyfunction]fnrun(){let pool = DuckdbConnectionManager::memory();println!("Connection pool created: {}", pool.is_ok());}}
Dockerfile
FROM mcr.microsoft.com/windows/servercore:ltsc2022
#Install Python 3.12.8
ADD https://www.python.org/ftp/python/3.12.8/python-3.12.8-amd64.exe /python-3.12.8.exe
RUN powershell.exe -Command \
$ErrorActionPreference = 'Stop'; \
Start-Process c:\python-3.12.8.exe -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait ; \
Remove-Item -Force python-3.12.8.exe;
SHELL ["cmd", "/S", "/C"]
#Latest VS Build Tools
ADD https://aka.ms/vs/17/release/vs_BuildTools.exe /vs_buildtools.exe
RUN vs_buildtools.exe --quiet --wait --norestart --nocache \
--installPath C:\BuildTools \
--add Microsoft.Component.MSBuild \
--add Microsoft.VisualStudio.Component.Windows10SDK.18362 \
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
ENTRYPOINT ["C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
# Latest Rust wit Rustup
ADD https://win.rustup.rs/x86_64 /rustup-init.exe
RUN start /w rustup-init.exe -y -v && echo "Error level is %ERRORLEVEL%"
RUN del rustup-init.exe
RUN setx /M PATH "C:\Users\ContainerAdministrator\.cargo\bin;%PATH%"
WORKDIR /app
COPY . .
RUN python -m venv .venv
RUN .venv\Scripts\activate.bat && pip install maturin==1.8.1
RUN .venv\Scripts\activate.bat && pip install pyarrow==18.1.0
RUN .venv\Scripts\activate.bat && maturin develop
RUN .venv\Scripts\activate.bat && python test-works.py
RUN .venv\Scripts\activate.bat && python test-fails.py
The text was updated successfully, but these errors were encountered:
Bug Description
The following example reproduces an issue with PyO3, DuckDB, and pyarrow on Windows. The issue is related to the import order of a custom PyO3 module with bundled duckdb (
pyo3_duckdb_pyarrow
) and thepyarrow
module.Tne problem only occurs on Windows. The code works on Linux.
Full project to reproduce can be found here: https://github.com/mracsko/pyo3_duckdb_pyarrow
I am not sure if the issue is strictly PyO3 related or maybe DuckDB, pyarrow, Python or Rust or the combination of those are causing the issue.
Steps to Reproduce
Build the provided Windows Container with Docker:
It is important to use Windows Containers.
Backtrace
Your operating system and version
Windows Container (mcr.microsoft.com/windows/servercore:ltsc2022)
Your Python version (
python --version
)3.12.8
Your Rust version (
rustc --version
)1.83.0
Your PyO3 version
0.23.4
How did you install python? Did you use a virtualenv?
Used venv, see installation details in the Dockerfile
Additional Info
Detailed Issue description
The issue is related to the import order of
pyo3_duckdb_pyarrow
module andpyarrow
. If thepyarrow
module is imported beforepyo3_duckdb_pyarrow
, the following error occurs on the run method of thepyo3_duckdb_pyarrow
module:The referred code is from the DuckDB crate:
The
assert_eq!(state, ffi::DuckDBSuccess);
lines fails becauselet state = unsafe { ffi::duckdb_create_config(&mut config) };
returnsffi::DuckDBError
.According to the documentation of (see here) this only can fail due to malloc issues:
... This will always succeed unless there is a malloc failure. ...
Works
If the module is loaded before
pyarrow
it works:Fails
If the module is loaded after
pyarrow
it fails:Versions
The container installs the following versions:
Additional notes
0.22.6
, but could be reproduced with0.23.4
.3.10.11
,3.12.8
and3.13.1
.Microsoft.VisualStudio.Component.Windows11SDK.22000
andMicrosoft.VisualStudio.Component.Windows10SDK.18362
.abi3-py311
andabi3-py38
.mcr.microsoft.com/windows/servercore:ltsc2022
andmcr.microsoft.com/windows:ltsc2019
.Files
Beside the above mentioned 2 test files, the following files are required to reproduce the issue.
Cargo.toml
pyproject.toml
src/lib.rs
Dockerfile
The text was updated successfully, but these errors were encountered: