| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
The loader in mssql_python/ddbc_bindings.py derived the architecture token of the compiled module from platform.machine(). On Windows that call reports the host CPU, not the architecture the interpreter was built for. An x64 CPython running on a Windows ARM64 machine, which is what the default python.org installer gives you, therefore looked for the arm64 .pyd while the installed win_amd64 wheel only ships the amd64 .pyd. The lookup missed on every import, a warning was printed to stdout, and the module was picked by directory order through the fallback branch. On Windows the architecture now comes from sysconfig.get_platform(), which is derived from the interpreter build and matches the wheel tag. Its platform string is reduced to the amd64, arm64 or win32 token and fed through the existing normalize_architecture() mapping, so the resulting file names are unchanged for native x64 and ARM64 installs. macOS and Linux keep using platform.machine() as before. The module search moved into find_module_path() and the fallback notice is now a RuntimeWarning instead of a print() call, so scripts whose stdout is parsed by other tools no longer receive a stray warning line. The fallback to the first matching file is kept as it was. tests/test_000_dependencies.py built its expected file name from platform.machine() as well, which made test_python_extension_exists fail on the same configuration. It now uses the loader's helper. New tests cover the x64 interpreter on an ARM64 host, the native ARM64 and x64 interpreters, the 32 bit interpreter, the non Windows passthrough, and the exact match, fallback warning and no match branches of find_module_path(). Refs microsoft#726
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Sorry, something went wrong.
There was a problem hiding this comment.
This PR fixes Windows native-extension selection in mssql_python/ddbc_bindings.py by deriving architecture from the running interpreter (via sysconfig.get_platform()) instead of the host CPU (platform.machine()), preventing unnecessary fallback loading (and stdout noise) when x64 Python runs on Windows ARM64.
Changes:
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| mssql_python/ddbc_bindings.py | Uses interpreter-derived Windows architecture and refactors module discovery into find_module_path() with warning-based fallback reporting. |
| tests/test_000_dependencies.py | Aligns dependency expectations with the loader and adds regression tests covering Windows ARM64 host + x64 interpreter and other architecture cases. |
| CHANGELOG.md | Documents the GH-726 loader fix and warning behavior change under Unreleased/Fixed. |
mssql_python/ddbc_bindings.py:164
warnings.warn(
f"Using fallback module file {module_files[0]} instead of {expected_module}",
RuntimeWarning,
)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
…ension The build names the 32 bit Windows artifact with the win32 token (pybind/build.bat and pybind/CMakeLists.txt both map x86 to win32), while the loader normalized the interpreter architecture to x86 and so looked for a file that is never produced. get_module_architecture now renames x86 to win32 the same way it already renames x64 to amd64, and the test for a 32 bit interpreter expects the token the build actually writes. The fallback notice is emitted with stacklevel 2 so the warning points at the import site rather than at the loader itself. Raised in review.
|
/azp run |
Sorry, something went wrong.
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Sorry, something went wrong.
Code Coverage Report
Files needing attentionmssql_python.pybind.logger_bridge.cpp: 59.2% mssql_python.pybind.ddbc_bindings.h: 61.5% mssql_python.pybind.logger_bridge.hpp: 70.8% mssql_python.pybind.ddbc_bindings.cpp: 75.5% mssql_python.__init__.py: 77.6% mssql_python.row.py: 77.6% mssql_python.pybind.connection.connection_pool.cpp: 81.4% mssql_python.pybind.connection.connection.cpp: 84.3% mssql_python.logging.py: 85.5% mssql_python.connection.py: 85.9% |
Sorry, something went wrong.
There was a problem hiding this comment.
Reviewed the PR for correctness, security, reliability, performance, test coverage, repository conventions, and applicable architecture and design specifications. No actionable issues were identified. The implementation is consistent with repository standards and the applicable approved design requirements.
Notes (non-blocking, no change required):
Sorry, something went wrong.
The fallback accepted any ddbc_bindings file with the right extension, so a binary built for another CPython version could be handed to importlib, which fails there with a confusing DLL or symbol error instead of a clean ImportError. The cpXY tags are version specific, so only files carrying this interpreter's tag are considered now, sorted so the pick is deterministic. A different architecture stays eligible, which keeps the case microsoftGH-726 cares about working.
…e' into fix/loader-interpreter-architecture
|
You are right, and it bit me while verifying: this Mac has only a cp314 build, and on a cp310 interpreter the old fallback handed it over and import died inside dlopen with a missing symbol, exactly the confusing failure you describe. The fallback now only considers files carrying this interpreter's version tag, sorted so the pick is deterministic, while a different architecture stays eligible so the GH-726 case keeps working. Took your test as suggested, plus one pinning the deterministic pick. The old fallback test asserted that a cp39 file satisfied a cp310 request, so it now uses a same version different architecture pair instead. Both new tests fail on the previous commit; the file is 35 passed with the change. |
Sorry, something went wrong.
|
Corrections look good to me! Approving the PR |
Sorry, something went wrong.
|
Thanks Jahnvi Thakkar (@jahnvi480)! The Python Linting failure was black asking for the fallback condition on a single line since it fits within the line length. Pushed the reformat in aa85a27, no logic changes. |
Sorry, something went wrong.
|
/azp run |
Sorry, something went wrong.
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Sorry, something went wrong.
Yes |
Sorry, something went wrong.
|
/azp run |
Sorry, something went wrong.
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR title: FIX: select the native extension by interpreter architecture on Windows
Branch: fix/loader-interpreter-architecture (local only, not pushed)
Work Item / Issue Reference
Summary
mssql_python/ddbc_bindings.py chose which compiled extension to load from platform.machine(). On Windows that reports the host CPU, not the architecture the running interpreter was built for. With an x64 CPython on a Windows ARM64 machine (the default python.org installer is x64 and pip installs the win_amd64 wheel), the loader looked for ddbc_bindings.cp314-arm64.pyd, which the wheel never shipped. The lookup missed on every import, a Warning: Using fallback module file ... line was printed to stdout, and the module was picked by directory order through the fallback branch.
Fix
Changes
Before (loader source executed with platform.system() = Windows, platform.machine() = ARM64, sysconfig.get_platform() = win-amd64, directory containing only ddbc_bindings.cp314-amd64.pyd):
After (same inputs):
Validation
Possible follow ups (not in this PR)