Skip to content

Commit 4974e30

Browse files
committed
Fix up error handling in message.insert.
1 parent 863f1c9 commit 4974e30

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

pymongo/message.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ def insert(collection_name, docs, check_keys, safe, last_error_args):
6868
max_bson_size = 0
6969
data = __ZERO
7070
data += bson._make_c_string(collection_name)
71-
encoded = [ bson.BSON.encode(doc, check_keys) for doc in docs ]
72-
max_bson_size = max(map(len, encoded))
73-
bson_data = "".join(encoded)
74-
if not bson_data:
71+
encoded = [bson.BSON.encode(doc, check_keys) for doc in docs]
72+
if not encoded:
7573
raise InvalidOperation("cannot do an empty bulk insert")
76-
data += bson_data
74+
max_bson_size = max(map(len, encoded))
75+
data += "".join(encoded)
7776
if safe:
7877
(_, insert_message) = __pack_message(2002, data)
7978
(request_id, error_message, _) = __last_error(last_error_args)

0 commit comments

Comments
 (0)