Skip to content

Commit 046324d

Browse files
committed
Removing double close
1 parent 377df69 commit 046324d

File tree

2 files changed

+2
-26
lines changed

2 files changed

+2
-26
lines changed

mssql_python/cursor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from mssql_python.constants import ConstantsDDBC as ddbc_sql_const
1717
from mssql_python.helpers import check_error, log
1818
from mssql_python import ddbc_bindings
19-
from mssql_python.exceptions import InterfaceError
19+
from mssql_python.exceptions import InterfaceError, ProgrammingError
2020
from .row import Row
2121

2222

@@ -438,7 +438,7 @@ def close(self) -> None:
438438
Close the cursor now (rather than whenever __del__ is called).
439439
"""
440440
if self.closed:
441-
return
441+
raise ProgrammingError("Cursor is already closed.")
442442

443443
if self.hstmt:
444444
self.hstmt.free()

tests/test_004_cursor.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,30 +1599,6 @@ def test_cursor_context_manager_enter_returns_self(db_connection):
15991599
# Cursor should be closed after context exit
16001600
assert cursor.closed
16011601

1602-
def test_double_close(db_connection):
1603-
"""Test that calling cursor.close() multiple times is idempotent and doesn't raise an exception"""
1604-
try:
1605-
cursor = db_connection.cursor()
1606-
1607-
# First close() call
1608-
cursor.close()
1609-
assert cursor.closed, "Cursor should be closed after first close() call"
1610-
1611-
# Second close() call - should be a no-op and not raise an exception
1612-
cursor.close()
1613-
assert cursor.closed, "Cursor should still be closed after second close() call"
1614-
1615-
# Multiple additional close() calls - should also be no-ops
1616-
cursor.close()
1617-
cursor.close()
1618-
assert cursor.closed, "Cursor should remain closed after multiple close() calls"
1619-
1620-
except Exception as e:
1621-
pytest.fail(f"Multiple cursor.close() calls test failed: {e}")
1622-
finally:
1623-
# Create a new cursor for any subsequent tests
1624-
cursor = db_connection.cursor()
1625-
16261602
def test_close(db_connection):
16271603
"""Test closing the cursor"""
16281604
try:

0 commit comments

Comments
 (0)