Skip to content

Commit 3f9c4b3

Browse files
Fixed bug when fetching an empty CLOB or BLOB column marked with the
"IS JSON" constraint (#429).
1 parent 7c4736b commit 3f9c4b3

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

doc/src/release_notes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Thick Mode Changes
3434
#) Fixed bug resulting in a segfault when using external authentication
3535
(`issue 425 <https://github.com/oracle/python-oracledb/issues/425>`__).
3636

37+
Common Changes
38+
++++++++++++++
39+
40+
#) Fixed bug when fetching an empty CLOB or BLOB column marked with the
41+
``IS JSON`` constraint
42+
(`issue 429 <https://github.com/oracle/python-oracledb/issues/429>`__).
43+
3744

3845
oracledb 2.5.0 (November 2024)
3946
------------------------------

src/oracledb/impl/base/cursor.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ cdef class BaseCursorImpl:
136136
value = value.read()
137137
if isinstance(value, bytes):
138138
value = value.decode()
139-
return json.loads(value)
139+
if value:
140+
return json.loads(value)
140141
return converter
141142

142143
cdef int _check_binds(self, uint32_t num_execs) except -1:

src/oracledb/impl/thin/cursor.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ cdef class AsyncThinCursorImpl(BaseThinCursorImpl):
256256
value = await value.read()
257257
if isinstance(value, bytes):
258258
value = value.decode()
259-
return json.loads(value)
259+
if value:
260+
return json.loads(value)
260261
return converter
261262

262263
async def _fetch_rows_async(self, object cursor):

tests/sql/create_schema.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ insert into &main_user..TestJsonCols values (1,
613613
'[1, 2, 3]', '[4, 5, 6]', utl_raw.cast_to_raw('[7, 8, 9]'))
614614
/
615615

616+
insert into &main_user..TestJsonCols values (2,
617+
'null', empty_clob(), empty_blob())
618+
/
619+
616620
commit
617621
/
618622

tests/test_4300_cursor_other.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,12 @@ def test_4359(self):
887887
)
888888
def test_4360(self):
889889
"4360 - fetch JSON columns as Python objects"
890-
expected_data = (1, [1, 2, 3], [4, 5, 6], [7, 8, 9])
891-
self.cursor.execute("select * from TestJsonCols")
892-
self.assertEqual(self.cursor.fetchone(), expected_data)
890+
expected_data = [
891+
(1, [1, 2, 3], [4, 5, 6], [7, 8, 9]),
892+
(2, None, None, None),
893+
]
894+
self.cursor.execute("select * from TestJsonCols order by IntCol")
895+
self.assertEqual(self.cursor.fetchall(), expected_data)
893896

894897
@unittest.skipIf(
895898
test_env.get_server_version() < (23, 1), "unsupported database"

tests/test_6300_cursor_other_async.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,15 @@ async def test_6350(self):
863863
(fetched_value,) = await self.cursor.fetchone()
864864
self.assertEqual(fetched_value, value)
865865

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

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

0 commit comments

Comments
 (0)