Skip to content

Commit

Permalink
fix(oracle): avoid double cursor closing by removing unnecessary `clo…
Browse files Browse the repository at this point in the history
…se` in `_fetch_from_cursor` (#9913)

Previously we were trying to close a cursor after an exception was
raised in `raw_sql`, which already closes the cursor in the case of an
exception. This is not allowed by the oracledb driver, so just close the
cursor on success.
  • Loading branch information
cpcloud authored Aug 26, 2024
1 parent 8b0fb66 commit a402095
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
15 changes: 2 additions & 13 deletions ibis/backends/oracle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,19 +623,8 @@ def _fetch_from_cursor(self, cursor, schema: sch.Schema) -> pd.DataFrame:

from ibis.backends.oracle.converter import OraclePandasData

try:
df = pd.DataFrame.from_records(
cursor, columns=schema.names, coerce_float=True
)
except Exception:
# clean up the cursor if we fail to create the DataFrame
#
# in the sqlite case failing to close the cursor results in
# artificially locked tables
cursor.close()
raise
df = OraclePandasData.convert_table(df, schema)
return df
df = pd.DataFrame.from_records(cursor, columns=schema.names, coerce_float=True)
return OraclePandasData.convert_table(df, schema)

def _clean_up_tmp_table(self, name: str) -> None:
with self.begin() as bind:
Expand Down
9 changes: 4 additions & 5 deletions ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
MySQLOperationalError,
MySQLProgrammingError,
OracleDatabaseError,
OracleInterfaceError,
PolarsInvalidOperationError,
PolarsPanicException,
PsycoPg2InternalError,
Expand Down Expand Up @@ -505,8 +504,8 @@ def test_date_truncate(backend, alltypes, df, unit):
),
pytest.mark.notyet(
["oracle"],
raises=OracleInterfaceError,
reason="cursor not open, probably a bug in the sql generated",
raises=OracleDatabaseError,
reason="ORA-01839: date not valid for month specified",
),
sqlite_without_ymd_intervals,
],
Expand Down Expand Up @@ -633,8 +632,8 @@ def convert_to_offset(offset, displacement_type=displacement_type):
),
pytest.mark.notyet(
["oracle"],
raises=OracleInterfaceError,
reason="cursor not open, probably a bug in the sql generated",
raises=OracleDatabaseError,
reason="ORA-01839: date not valid for month specified",
),
sqlite_without_ymd_intervals,
],
Expand Down

0 comments on commit a402095

Please sign in to comment.