Skip to content

Commit da2d088

Browse files
Variables saved with Cursor.setinputsizes() are now forgotten when an
exception is raised (#411).
1 parent 06d1fb2 commit da2d088

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ Common Changes
8080
#) Improved error message when attempting to access attributes on a connection
8181
before a connection has been established
8282
(`issue 385 <https://github.com/oracle/python-oracledb/issues/385>`__).
83+
#) The variables saved with :meth:`Cursor.setinputsizes()` are now forgotten
84+
when an exception is raised
85+
(`issue 411 <https://github.com/oracle/python-oracledb/issues/411>`__).
8386
#) Fixed bug when calling :meth:`ConnectParams.set()` with a value of ``None``
8487
for the ``connectiontype`` and ``session_callback`` parameters. Previously,
8588
any values set earlier would be improperly cleared and now they are

src/oracledb/impl/base/cursor.pyx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,17 @@ cdef class BaseCursorImpl:
393393
self.bind_style is dict and not isinstance(parameters, dict)
394394
or self.bind_style is not dict and isinstance(parameters, dict)
395395
):
396+
self.set_input_sizes = False
396397
errors._raise_err(errors.ERR_MIXED_POSITIONAL_AND_NAMED_BINDS)
397398

398399
# prepare statement, if necessary
399-
if prepare_needed:
400-
self._prepare(statement, None, True)
400+
try:
401+
if prepare_needed:
402+
self._prepare(statement, None, True)
403+
finally:
404+
self.set_input_sizes = False
401405

402406
# perform bind
403-
self.set_input_sizes = False
404407
if parameters is not None:
405408
self.bind_one(cursor, parameters)
406409

@@ -417,11 +420,13 @@ cdef class BaseCursorImpl:
417420
# prepare statement, if necessary
418421
if statement is None and self.statement is None:
419422
errors._raise_err(errors.ERR_NO_STATEMENT)
420-
elif statement is not None and statement != self.statement:
421-
self._prepare(statement, None, True)
423+
try:
424+
if statement is not None and statement != self.statement:
425+
self._prepare(statement, None, True)
426+
finally:
427+
self.set_input_sizes = False
422428

423429
# perform bind, if applicable
424-
self.set_input_sizes = False
425430
if isinstance(parameters, int):
426431
num_execs = parameters
427432
if self.bind_vars is not None:

tests/test_4300_cursor_other.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,16 @@ def test_4367(self):
989989
cursor.parse("insert into TestTempTable (IntCol) values (:1)")
990990
cursor.execute(None, [1])
991991

992+
def test_4368(self):
993+
"4368 - test cursor.setinputsizes() with early failed execute"
994+
self.cursor.setinputsizes(a=int, b=str)
995+
with self.assertRaisesFullCode("DPY-2006"):
996+
self.cursor.execute("select :c from dual", [5])
997+
value = 4368
998+
self.cursor.execute("select :d from dual", [value])
999+
(fetched_value,) = self.cursor.fetchone()
1000+
self.assertEqual(fetched_value, value)
1001+
9921002

9931003
if __name__ == "__main__":
9941004
test_env.run_test_cases()

tests/test_6300_cursor_other_async.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,16 @@ async def test_6349(self):
853853
)
854854
await cursor.execute(None, [1])
855855

856+
async def test_6350(self):
857+
"6350 - test cursor.setinputsizes() with early failed execute"
858+
self.cursor.setinputsizes(a=int, b=str)
859+
with self.assertRaisesFullCode("DPY-2006"):
860+
await self.cursor.execute("select :c from dual", [5])
861+
value = 4368
862+
await self.cursor.execute("select :d from dual", [value])
863+
(fetched_value,) = await self.cursor.fetchone()
864+
self.assertEqual(fetched_value, value)
865+
856866

857867
if __name__ == "__main__":
858868
test_env.run_test_cases()

0 commit comments

Comments
 (0)