You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
importmssql_pythonconn=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
Emil Tveden Bjerglund (@ebj-jyskebank-dk) - thanks a lot for raising this issue & sharing the examples.
we'll get back to you on this as we triage this further this week
Emil Tveden Bjerglund (@ebj-jyskebank-dk) Thank you for raising this issue and making our driver better. We have merged the PR for supporting Row object, it will be available in our upcoming release.
Activity
[-]Cannot cast Row object as tuple[/-][+]Bulkcopy: Cannot cast Row object as tuple[/+]github-actions commentedon Mar 23, 2026
Hi Emil Tveden Bjerglund (@ebj-jyskebank-dk), thank you for opening this issue!
Our team will review it shortly. We aim to triage all new issues within 24-48 hours and get back to you.
If you have additional information to share, please feel free to update the issue.
Thank you for your patience!
bewithgaurav commentedon Apr 6, 2026
Emil Tveden Bjerglund (@ebj-jyskebank-dk) - thanks a lot for raising this issue & sharing the examples.
we'll get back to you on this as we triage this further this week
Address review: remove list branch, fix type hint and docstring (GH-482)
REVIEW: Rename to _prepare_row_iterator, use itertools.chain, add reg…
FEAT: Accept Row objects in bulkcopy without manual tuple conversion (#…
jahnvi480 commentedon Jun 11, 2026
Emil Tveden Bjerglund (@ebj-jyskebank-dk) Thank you for raising this issue and making our driver better. We have merged the PR for supporting Row object, it will be available in our upcoming release.