Skip to content

Commit

Permalink
Fixed bug when fetching an empty CLOB or BLOB column marked with the
Browse files Browse the repository at this point in the history
"IS JSON" constraint (#429).
  • Loading branch information
anthony-tuininga committed Dec 6, 2024
1 parent 7c4736b commit 3f9c4b3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
7 changes: 7 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ Thick Mode Changes
#) Fixed bug resulting in a segfault when using external authentication
(`issue 425 <https://github.com/oracle/python-oracledb/issues/425>`__).

Common Changes
++++++++++++++

#) Fixed bug when fetching an empty CLOB or BLOB column marked with the
``IS JSON`` constraint
(`issue 429 <https://github.com/oracle/python-oracledb/issues/429>`__).


oracledb 2.5.0 (November 2024)
------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/oracledb/impl/base/cursor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ cdef class BaseCursorImpl:
value = value.read()
if isinstance(value, bytes):
value = value.decode()
return json.loads(value)
if value:
return json.loads(value)
return converter

cdef int _check_binds(self, uint32_t num_execs) except -1:
Expand Down
3 changes: 2 additions & 1 deletion src/oracledb/impl/thin/cursor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ cdef class AsyncThinCursorImpl(BaseThinCursorImpl):
value = await value.read()
if isinstance(value, bytes):
value = value.decode()
return json.loads(value)
if value:
return json.loads(value)
return converter

async def _fetch_rows_async(self, object cursor):
Expand Down
4 changes: 4 additions & 0 deletions tests/sql/create_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ insert into &main_user..TestJsonCols values (1,
'[1, 2, 3]', '[4, 5, 6]', utl_raw.cast_to_raw('[7, 8, 9]'))
/

insert into &main_user..TestJsonCols values (2,
'null', empty_clob(), empty_blob())
/

commit
/

Expand Down
9 changes: 6 additions & 3 deletions tests/test_4300_cursor_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,12 @@ def test_4359(self):
)
def test_4360(self):
"4360 - fetch JSON columns as Python objects"
expected_data = (1, [1, 2, 3], [4, 5, 6], [7, 8, 9])
self.cursor.execute("select * from TestJsonCols")
self.assertEqual(self.cursor.fetchone(), expected_data)
expected_data = [
(1, [1, 2, 3], [4, 5, 6], [7, 8, 9]),
(2, None, None, None),
]
self.cursor.execute("select * from TestJsonCols order by IntCol")
self.assertEqual(self.cursor.fetchall(), expected_data)

@unittest.skipIf(
test_env.get_server_version() < (23, 1), "unsupported database"
Expand Down
9 changes: 9 additions & 0 deletions tests/test_6300_cursor_other_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,15 @@ async def test_6350(self):
(fetched_value,) = await self.cursor.fetchone()
self.assertEqual(fetched_value, value)

async def test_6351(self):
"4360 - fetch JSON columns as Python objects"
expected_data = [
(1, [1, 2, 3], [4, 5, 6], [7, 8, 9]),
(2, None, None, None),
]
await self.cursor.execute("select * from TestJsonCols order by IntCol")
self.assertEqual(await self.cursor.fetchall(), expected_data)


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

0 comments on commit 3f9c4b3

Please sign in to comment.