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

bulkcopy accepts four-part table names that SQL Server always rejects

未关闭 适合新手
#843 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python, sql
领域
databases

调研方向

部件数量上限是批量复制标识符解析器中的常量 MAX_PARTS,目前允许四个部件;修改从这里开始。将上限降为三,使四个部件的目标在任何服务器调用之前,就以与负载中五个部件相同的用法错误失败。完成的标准是:复现用例中的四个部件情况抛出用法错误,且不会进入元数据查询;三个部件和五个部件的情况仍按描述运行。

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

描述

area: bulk-copy
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

环境准备

在 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 摘要。