Merge origin/main into bewithgaurav/profiling · microsoft/mssql-python@417a8c7 · GitHub
Skip to content

Commit 417a8c7

Browse files
bewithgauravCopilot
andcommitted
Merge origin/main into bewithgaurav/profiling
Pick up 1.11.0 release, context-manager transaction (#639), bulkcopy timeout (#650), py-core 0.1.6, and macOS dylib config (#661). No profiler conflicts; auto-merge clean. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2 parents 321a22c + d94debd commit 417a8c7

16 files changed

Lines changed: 1050 additions & 35 deletions

‎PyPI_Description.md‎

Lines changed: 6 additions & 7 deletions

‎eng/versions/mssql-py-core.version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.5
1+
0.1.6

‎mssql_python/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .helpers import Settings, get_settings, _settings, _settings_lock
1515

1616
# Driver version
17-
__version__ = "1.10.0"
17+
__version__ = "1.11.0"
1818

1919
# Exceptions
2020
# https://www.python.org/dev/peps/pep-0249/#exceptions

‎mssql_python/connection.py‎

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,16 +1703,51 @@ def __enter__(self) -> "Connection":
17031703
logger.info("Entering connection context manager.")
17041704
return self
17051705

1706-
def __exit__(self, *args: Any) -> None:
1706+
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
17071707
"""
17081708
Exit the context manager.
17091709
1710-
Closes the connection when exiting the context, ensuring proper
1711-
resource cleanup. This follows the modern standard used by most
1712-
database libraries.
1710+
Implements commit-on-success / rollback-on-exception semantics:
1711+
- If the block exits cleanly and autocommit is off, the transaction
1712+
is committed.
1713+
- If an exception is raised and autocommit is off, the transaction
1714+
is rolled back.
1715+
- The connection is always closed when leaving the block.
1716+
1717+
If commit() fails on clean exit, the connection is closed and the
1718+
commit exception is raised. On exception exit, cleanup failures
1719+
(rollback or close) are suppressed so the original user exception
1720+
propagates unchanged.
17131721
"""
1714-
if not self._closed:
1722+
if self._closed:
1723+
return
1724+
try:
1725+
if not self.autocommit:
1726+
if exc_type is None:
1727+
self.commit()
1728+
else:
1729+
self.rollback()
1730+
except Exception:
1731+
try:
1732+
self.close()
1733+
except Exception:
1734+
logger.warning(
1735+
"Failed to close connection after failed "
1736+
"commit/rollback in context manager.",
1737+
exc_info=True,
1738+
)
1739+
if exc_type is None:
1740+
raise
1741+
return
1742+
try:
17151743
self.close()
1744+
except Exception:
1745+
if exc_type is None:
1746+
raise
1747+
logger.warning(
1748+
"Failed to close connection in context manager.",
1749+
exc_info=True,
1750+
)
17161751

17171752
def __del__(self) -> None:
17181753
"""

‎mssql_python/cursor.py‎

Lines changed: 14 additions & 0 deletions
-448 Bytes
Binary file not shown.
8.1 KB
Binary file not shown.
-544 Bytes
Binary file not shown.
18.1 KB
Binary file not shown.
41.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)