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
-
Atomic append fails to create a missing file可能已有人在做 @harbinresearcher 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 70/100
fabiocaccamo/python-fsutil#201 ·
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
task
難度 2/5 1-3 小時 新手友好度 78/100
danparshall/claude_researcher#87 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 62/100
GhostManager/Ghostwriter#998 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 85/100
datajoint/datajoint-python#1586 ·
維護者通常 1 天內回覆