Skip to content

Bulkcopy: Cannot cast Row object as tuple #482

Description

@ebj-jyskebank-dk

List of Rows from cursor.fetchall() cannot be used directly in bulkcopy

Data retrieved using cursor.fetchall() is of type List[Row]. Intuitively I would expect to be able to use these objects directly in cursor.bulkcopy(), but I get an exception.

  File "/home/vscode/.local/lib/python3.14/site-packages/mssql_python/cursor.py", line 2706, in bulkcopy
    raise type(e)(str(e)) from None
ValueError: Expected tuple, got: 'Row' object cannot be cast as 'tuple'

To reproduce

import mssql_python

conn = mssql_python.connect("...")
cursor = conn.cursor()

cursor.execute(f"SELECT TOP 10 * FROM table_A")
data = cursor.fetchall()
copy_result = cursor.bulkcopy("table_B", data)

conn.close()

(This is a simplified example - in reality I stumpled on this while trying to migrate data between two databases on different servers).

Expected behavior

I expected the bulkcopy method to accept a data argument of type List[Row].

Further technical details

Python version: 3.14
SQL Server version: Microsoft SQL Azure 12.0.2000.8
Operating system: Linux 39a7e4bda3b8 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 GNU/Linux

Metadata

Metadata

Assignees

Labels

area: bulk-copyIssues in cursor.bulkcopy()enhancementNew feature or requestinADOtriage doneIssues that are triaged by dev team and are in investigation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions