Skip to content

Commit a9c11fc

Browse files
Fixed bug when attempting to append an element to a DbObject which is
not actually a collection.
1 parent 72993e8 commit a9c11fc

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Common Changes
6666
(`issue 525 <https://github.com/oracle/python-oracledb/issues/525>`__).
6767
#) Fixed bug when attempting to convert an integer that cannot be represented
6868
as a native C ``int`` value to an Arrow data frame.
69+
#) Fixed bug when attempting to append an element to a
70+
:ref:`DbObject <dbobjecttype>` which is not actually a collection.
6971
#) API documentation is now generated from the source code.
7072
#) Internal change: typing_extensions is now a dependency.
7173

src/oracledb/dbobject.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def append(self, element: Any) -> None:
9191
creates an element immediately following the highest index available in
9292
the collection.
9393
"""
94+
self._ensure_is_collection()
9495
self._impl.append(element)
9596

9697
def asdict(self) -> dict:

tests/test_2300_object_var.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,39 @@ def test_2347(self):
939939
expected_data = [[4, 8], None, [1, 3, 5], None, [2, 6, 10, 7, 9]]
940940
self.assertEqual(plain_obj, expected_data)
941941

942+
def test_2348(self):
943+
"2348 - test using collection methods on an object that is not one"
944+
obj_type = self.conn.gettype("UDT_OBJECT")
945+
obj = obj_type.newobject()
946+
with self.assertRaisesFullCode("DPY-2036"):
947+
obj.append(5)
948+
with self.assertRaisesFullCode("DPY-2036"):
949+
obj.asdict()
950+
with self.assertRaisesFullCode("DPY-2036"):
951+
obj.aslist()
952+
with self.assertRaisesFullCode("DPY-2036"):
953+
obj.delete(5)
954+
with self.assertRaisesFullCode("DPY-2036"):
955+
obj.exists(5)
956+
with self.assertRaisesFullCode("DPY-2036"):
957+
obj.extend([5])
958+
with self.assertRaisesFullCode("DPY-2036"):
959+
obj.first()
960+
with self.assertRaisesFullCode("DPY-2036"):
961+
obj.getelement(5)
962+
with self.assertRaisesFullCode("DPY-2036"):
963+
obj.last()
964+
with self.assertRaisesFullCode("DPY-2036"):
965+
obj.next(5)
966+
with self.assertRaisesFullCode("DPY-2036"):
967+
obj.prev(5)
968+
with self.assertRaisesFullCode("DPY-2036"):
969+
obj.setelement(5, None)
970+
with self.assertRaisesFullCode("DPY-2036"):
971+
obj.size()
972+
with self.assertRaisesFullCode("DPY-2036"):
973+
obj.trim(0)
974+
942975

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

0 commit comments

Comments
 (0)