Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

bulkcopy_arrow() / bulkcopy()` broken in 1.16.0

未关闭
#855 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@jahnvi480 已经在做这个了。

开始于 2026年10月22日。

  • #860 来自 @jahnvi480 —— 未关闭

评估

难度
3/5
预计耗时
半天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
database

调研方向

Start by reading mssql_python/cursor.py at the bulkcopy_arrow() implementation and trace how it imports and uses mssql_py_core; inspect the corresponding bulkcopy() path too. Reproduce the reported import behavior with the 1.16.0 Windows package and check where the connection classes are exposed. Done when both bulk copy methods can access the connection class after a clean 1.16.0 install.

由索引模型根据 Issue 内容生成。

描述

area: bulk-copy bug inADO triage done under development

Title

bulkcopy_arrow() / bulkcopy() broken in 1.16.0: AttributeError: module 'mssql_py_core' has no attribute 'PyCoreConnection'

Description

After upgrading from 1.15.0 to 1.16.0, any call to cursor.bulkcopy_arrow(...) (and presumably cursor.bulkcopy(...), which shares the same pycore connection path) fails immediately with:

AttributeError: module 'mssql_py_core' has no attribute 'PyCoreConnection'

Full traceback:

File ".../site-packages/mssql_python/cursor.py", line 3764, in bulkcopy_arrow
    pycore_connection = mssql_py_core.PyCoreConnection(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'mssql_py_core' has no attribute 'PyCoreConnection'

This reproduces on a clean pip install mssql-python==1.16.0 with no other code changes — the exact same script works correctly against 1.15.0.

Root cause

This looks like a packaging regression from the 1.16.0 change that split the Rust runtime out into a separate version-matched mssql-python-rs package (per the 1.16.0 release notes).

On Windows, after pip install mssql-python==1.16.0, the compiled extension lands at:

site-packages/mssql_py_core/mssql_py_core.pyd

There is no __init__.py inside site-packages/mssql_py_core/. As a result, import mssql_py_core resolves to an empty implicit namespace package (PEP 420) rather than loading the compiled extension — so mssql_py_core.PyCoreConnection doesn't exist at that path.

The compiled extension itself is fine and fully functional — it just needs to be imported one level deeper:

import mssql_py_core.mssql_py_core as core
print([a for a in dir(core) if "Connection" in a])
# -> ['PyAsyncConnection', 'PyCoreConnection']

But mssql_python/cursor.py's bulkcopy_arrow (and likely bulkcopy) does a plain top-level import mssql_py_core and then calls mssql_py_core.PyCoreConnection(...) directly, which hits the empty namespace package instead of the real module.

Likely fix: either (a) add an __init__.py to the mssql_py_core package in the mssql-python-rs wheel that re-exports from the nested mssql_py_core.mssql_py_core extension module, or (b) update mssql-python's internal imports to reference mssql_py_core.mssql_py_core explicitly.

Environment

  • mssql-python: 1.16.0 (regression; works correctly on 1.15.0)
  • mssql-python-rs: 0.3.0
  • mssql-python-odbc: 18.6.2.2
  • Python: 3.11.0
  • OS: Windows 10/11 (Windows-10-10.0.26200-SP0), x86_64
  • Install method: pip install mssql-python==1.16.0 (clean upgrade from 1.15.0 in an existing venv)

Reproduction steps

pip install mssql-python==1.16.0
python -c "
import mssql_python
cn = mssql_python.connect('SERVER=...;DATABASE=...;Trusted_Connection=yes;')
cur = cn.cursor()
cur.bulkcopy_arrow('some_table', some_pyarrow_record_batch_reader)
"

Minimal repro of the underlying import issue (no SQL Server connection needed):

import mssql_py_core
print(mssql_py_core.__file__)          # None -- confirms empty namespace package
print(hasattr(mssql_py_core, "PyCoreConnection"))  # False

import mssql_py_core.mssql_py_core as core
print(core.__file__)                   # points to the real .pyd
print(hasattr(core, "PyCoreConnection"))  # True

Expected behavior

import mssql_py_core should expose PyCoreConnection (and PyAsyncConnection) at the top level, as it presumably did before the 1.16.0 packaging split, so bulkcopy_arrow()/bulkcopy() work without modification.

Actual behavior

bulkcopy_arrow() / bulkcopy() are completely broken on 1.16.0 for Windows installs via pip, with no workaround short of pinning back to 1.15.0.

Impact

This blocks all bulk-copy / Arrow bulk-load workflows on 1.16.0. We've rolled back to 1.15.0 in the meantime.

主要语言
Python
星标
479
派生
62
平均合并
2 天 9 小时
30 天内合并 PR
18

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/mssql-python 的其他 Issue

查看 microsoft/mssql-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。