Repository navigation
FEAT: TVP support for async queries - #814
Conversation
Expose native TVP and SQL type-hint helpers lazily. Support iterable executemany batches and preserve result state on iteration failure. Add cursor closed-state reporting, document async result contracts, and cover these behaviors with async integration tests.
PR Performance Report✅ No regression detectedNo consistent slowdowns detected across all 2 environments. 0 IMPROVEMENTS 0 SLOWDOWNS 2/2 ENVIRONMENTS Coverage: 2 of 2 environments completed. Advisory result; does not block merging. Performance diagnosticsPhase times are inclusive diagnostics and must not be added together. They identify where measured time changed, not why it changed. No affected phases or call-count changes were recorded. All database tasks and timingsUnix / SQL Server 2022
Unix / SQL Server 2025
Build and measurement detailsPR head:
A consistent change requires more than 20% median paired movement, at least 1 ms between the median runtimes, and at least 80% of pairs exceeding the relative threshold in the same direction. A slowdown without enough pair agreement is reported as inconsistent. The displayed change is the median of paired before-and-after ratios. It is not recalculated from the two displayed median runtimes. Both revisions use profiling-enabled builds on the same agent and database, with alternating order and discarded warmups. Results are diagnostic and do not represent production-wheel latency. Raw samples and logs are attached to the ADO run as |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Guard the optional native dependency test and complete the required PR metadata.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Adds preview async TVP/type-hint support, iterable executemany, cursor state reporting, and expanded integration tests.
Changes:
- Adds lazy native TVP and SQL type-hint exports.
- Supports synchronous iterable batches and failure-result preservation.
- Documents and tests async cursor/result behavior.
| File | Summary |
|---|---|
tests/AsyncTest/test_006_async_execute.py |
Tests iterable batches, TVPs, and type hints. |
tests/AsyncTest/test_005_async_cursor.py |
Tests cursor state and result behavior. |
tests/AsyncTest/test_004_async_logging.py |
Updates execution logging expectations. |
tests/AsyncTest/test_001_async_query_native.py |
Tests native exports. Finding: moderate, 2 votes—add an importorskip guard for the optional dependency at lines 55 and 65. |
mssql_python/async_query/async_execute.py |
Adds iterable batch execution and failure handling. |
mssql_python/async_query/async_cursor.py |
Adds cursor state and result-contract documentation. |
mssql_python/async_query/__init__.py |
Adds lazy native exports. Finding: nit, 1 vote—replace PR placeholders and empty summary with valid metadata. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Fix the indentation error that prevents the native async test module from being collected.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
Resolved since last review (1)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
mssql_python/async_query/async_execute.pyLines 101-116 101 def parameter_rows():
102 nonlocal iteration_error
103 try:
104 iterator = iter(seq_of_parameters)
! 105 except BaseException as error:
! 106 iteration_error = error
! 107 raise
108 while True:
109 try:
110 row = next(iterator)
111 except StopIteration:
! 112 return
113 except BaseException as error:
114 iteration_error = error
115 raise
116 yield row📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.performance_counter.hpp: 0.7%
mssql_python.pybind.logger_bridge.cpp: 57.9%
mssql_python.pybind.ddbc_bindings.h: 62.6%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.connection.connection_pool.cpp: 81.3%
mssql_python.pybind.connection.connection.cpp: 82.5%
mssql_python.logging.py: 86.2%
mssql_python.pooling.py: 90.1%
mssql_python.pybind.fetch_temporal.hpp: 92.1%
mssql_python.cursor.py: 92.5%🔗 Quick Links
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Iterator error handling can replace row-validation failures with GeneratorExit, bypassing ordinary exception handlers, and strip explicit exception causes needed for root-cause diagnostics.
2 open issues
2 resolved since last review
Review effort: Balanced
Refactor parameter_rows to use an iterator for seq_of_parameters. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
TVP serialization, metadata fidelity, and pre-dispatch iterable validation depend on unavailable native code and require verification against the pinned dependency and a live SQL Server.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
TVP metadata, serialization, and pre-dispatch iterable validation depend on native code absent from this snapshot and require SQL Server integration validation unavailable in this review environment.
No open issues 🎉
Review effort: Balanced


Work Item / Issue Reference
Summary
This pull request introduces several improvements and enhancements to the
mssql_python.async_queryasync API, focusing on better native type integration, more robust and consistent cursor behavior, and improved handling of parameter iterables inexecutemany. It also expands the test suite to cover these changes and edge cases.Key highlights include:
executemany.closedproperty.Native type integration and exports
SQL_MONEY,SQL_SMALLMONEY,SQL_XML,SQL_JSON,SQL_VECTOR) and the internal_TableValuedParameterconstructor, with dynamic loading and error reporting if the native dependency is missing. These are now included in__all__anddir()as appropriate.AsyncCursor API and behavior improvements
closedproperty to async cursors to reflect both wrapper and parent connection state, with tests for idempotency and parent connection closure propagation.nextset,close,description, androwcountto document async-specific behaviors and differences from the synchronous API.nextsetcorrectly tracksrowcountanddescriptionper result, including edge cases.Executemany and parameter iterable handling
executemanysignatures to accept any synchronous iterable (not just sequences), improved error handling for non-iterables, and ensured iterables are consumed only once. Streaming/asynchronous iterables are explicitly not supported.Logging and test adjustments
batch_countforexecutemanyand adjusted test expectations accordingly.These changes make the async query API more robust, Pythonic, and consistent with both native and DB-API expectations.