Skip to content

Commit aa9b1da

Browse files
Fixed bug returning metadata of SODA documents inserted into a collection
using saveAndGet().
1 parent b0f0c67 commit aa9b1da

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Thin Mode Changes
1919
Thick Mode Changes
2020
++++++++++++++++++
2121

22+
#) Fixed bug returning metadata of SODA documents inserted into a collection
23+
using :meth:`SodaCollection.saveAndGet()`.
24+
2225
Common Changes
2326
++++++++++++++
2427

src/oracledb/soda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def saveAndGet(self, doc: object, hint: str=None) -> Type["SodaDocument"]:
318318
doc_impl = self._process_doc_arg(doc)
319319
if hint is not None and not isinstance(hint, str):
320320
raise TypeError("expecting a string")
321-
return_doc_impl = self._impl.save(doc_impl, hint, return_doc=False)
321+
return_doc_impl = self._impl.save(doc_impl, hint, return_doc=True)
322322
return SodaDocument._from_impl(return_doc_impl)
323323

324324
def truncate(self) -> None:

tests/test_3400_soda_collection.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,5 +446,27 @@ def test_3419_save_and_get_with_hint(self):
446446
result, = cursor.fetchone()
447447
self.assertTrue(hint in result.read())
448448

449+
def test_3420_save_and_get(self):
450+
"3420 - test saveAndGet"
451+
soda_db = self.get_soda_database(minclient=(19, 9))
452+
coll = soda_db.createCollection("TestSodaSaveAndGet")
453+
coll.find().remove()
454+
values_to_save = [
455+
dict(name="John", age=50),
456+
soda_db.createDocument(dict(name="Mark", age=45)),
457+
soda_db.createDocument(dict(name="Jill", age=32))
458+
]
459+
inserted_keys = []
460+
for value in values_to_save:
461+
doc = coll.saveAndGet(value)
462+
inserted_keys.append(doc.key)
463+
fetched_docs = coll.find().getDocuments()
464+
self.connection.commit()
465+
self.assertEqual(coll.find().count(), len(values_to_save))
466+
for key, fetched_doc in zip(inserted_keys, fetched_docs):
467+
doc = coll.find().key(key).getOne()
468+
self.assertEqual(doc.getContent(), fetched_doc.getContent())
469+
coll.drop()
470+
449471
if __name__ == "__main__":
450472
test_env.run_test_cases()

0 commit comments

Comments
 (0)