fix(insert_many): list instead of set to maintain order (#18641)

This commit is contained in:
Faris Ansari 2022-10-28 14:37:17 +05:30 committed by GitHub
parent d35aa6c545
commit aa8957e785
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -206,9 +206,9 @@ def insert_many(docs=None):
if len(docs) > 200: if len(docs) > 200:
frappe.throw(_("Only 200 inserts allowed in one request")) frappe.throw(_("Only 200 inserts allowed in one request"))
out = set() out = []
for doc in docs: for doc in docs:
out.add(insert_doc(doc).name) out.append(insert_doc(doc).name)
return out return out

View file

@ -227,15 +227,18 @@ class TestClient(FrappeTestCase):
"parent": note1.name, "parent": note1.name,
"parentfield": "seen_by", "parentfield": "seen_by",
}, },
{"doctype": "Note", "title": "not-a-random-title", "content": "test"},
{"doctype": "Note", "title": get_random_title(), "content": "test"}, {"doctype": "Note", "title": get_random_title(), "content": "test"},
{"doctype": "Note", "title": get_random_title(), "content": "test"}, {"doctype": "Note", "title": get_random_title(), "content": "test"},
{"doctype": "Note", "title": "another-note-title", "content": "test"},
] ]
# insert all docs # insert all docs
docs = insert_many(doc_list) docs = insert_many(doc_list)
# make sure only 1 name is returned for the parent upon insertion of child docs self.assertEqual(len(docs), 7)
self.assertEqual(len(docs), 3) self.assertEqual(docs[3], "not-a-random-title")
self.assertEqual(docs[6], "another-note-title")
self.assertIn(note1.name, docs) self.assertIn(note1.name, docs)
# cleanup # cleanup