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