bulkcopy accepts four-part table names that SQL Server always rejects
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
部件数量上限是批量复制标识符解析器中的常量 MAX_PARTS,目前允许四个部件;修改从这里开始。将上限降为三,使四个部件的目标在任何服务器调用之前,就以与负载中五个部件相同的用法错误失败。完成的标准是:复现用例中的四个部件情况抛出用法错误,且不会进入元数据查询;三个部件和五个部件的情况仍按描述运行。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
The 1.16.0 bulk copy identifier parser allows up to four name parts (MAX_PARTS is 4), so cursor.bulkcopy() accepts server.database.schema.table. SQL Server doesn't allow a server prefix on a bulk insert target, so every four-part name fails with error 117 after metadata lookup starts. A five-part name fails earlier, in the driver, with a clear usage error.
Exception message:
RuntimeError: Sql Error: 117: Class 15: State 1: The object name 'dlevy-sql25.test1.dbo.fp116' contains more than the maximum number of prefixes. The maximum is 2. on dlevy-sql25 in at line 1
For comparison, a five-part name:
RuntimeError: Failed to retrieve destination metadata: Usage Error: Too many identifier parts: 5 (maximum is 4)
To reproduce
import os
import mssql_python
conn = mssql_python.connect(os.environ["SQL_CONNECTION_STRING"], timeout=30)
cur = conn.cursor()
cur.execute("CREATE TABLE dbo.fp116 (i int)")
conn.commit()
server = cur.execute("SELECT @@SERVERNAME").fetchval()
try:
cur.bulkcopy(f"[{server}].test1.dbo.fp116", [(1,)])
except Exception as e:
print(type(e).__name__, e)
try:
cur.bulkcopy("a.b.c.d.e", [(1,)])
except Exception as e:
print(type(e).__name__, e)
cur.execute("DROP TABLE dbo.fp116")
conn.commit()
Expected behavior
The parser should allow at most three parts for a bulk copy target and reject a four-part name with the same kind of usage error it gives for five parts, before it contacts the server. The current limit of four suggests linked-server targets work, but they can't.
Further technical details
Python version: 3.14.0
mssql-python: 1.16.0 (pip), default msodbcsql18 provider
SQL Server version: SQL Server 2025 (RTM-CU9) 17.0.5005.3, Enterprise Edition, EngineEdition 3
Operating system: Windows 11
Additional context
Found while documenting the 1.16.0 bulk copy identifier changes in MicrosoftDocs/sql-docs-pr#38337. The docs now list one-part through three-part names and say that SQL Server rejects the four-part form.
- 主要语言
- Python
- 星标
- 478
- 派生
- 62
- 平均合并
- 3 天 1 小时
- 30 天内合并 PR
- 27
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/mssql-python 的其他 Issue
-
macOS: encrypted connections fail after Homebrew moved the `openssl` alias to `openssl@4`可能已有人在做 @bewithgaurav 于 13 天前认领。 未关闭area: packaging-platform bug triage needed
难度 4/5 3-5 天 新手友好度 55/100
microsoft/mssql-python#826 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
bulkcopy PyCore login is closed by SQL Server 2019 while ODBC and Go clients succeed (1.14.0)可能重新可做 @bewithgaurav 于 34 天前认领,目前没有进行中的 PR。 未关闭area: bulk-copy bug triage done
microsoft/mssql-python#750 · 4 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Announcement: mssql-python is coming to Django through mssql-django 2.0可能重新可做 @bewithgaurav 于 40 天前认领,目前没有进行中的 PR。 未关闭announcement
microsoft/mssql-python#748 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Connection pool can briefly exceed max_size when pooling is disabled under load可能已有人在做 @bewithgaurav 于 22 天前认领。 未关闭area: connectivity-auth bug triage done under development
难度 4/5 3-5 天 新手友好度 62/100
microsoft/mssql-python#746 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Decimal in money range still string-binds on the executemany path可能已有人在做 @bewithgaurav 于 22 天前认领。 未关闭area: data-types bug triage done under development
难度 4/5 3-5 天 新手友好度 48/100
microsoft/mssql-python#745 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 microsoft/mssql-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
task
难度 2/5 1-3 小时 新手友好度 78/100
danparshall/claude_researcher#87 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 85/100
datajoint/datajoint-python#1586 ·
维护者通常 1 天内回复
-
1D intercept of length 1 is accepted as `fix_params` in population GLM with more than 1 unit可能已有人在做 @dhvani7014 今天认领。 未关闭bug good first issue
难度 2/5 1-3 小时 新手友好度 72/100
flatironinstitute/nemos#642 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 78/100
uniswap-python/uniswap-python#487 ·