@@ -1565,30 +1565,29 @@ _batched_write_command(
15651565 /* We have enough data, return this batch.
15661566 * max_cmd_size accounts for the two trailing null bytes.
15671567 */
1568+ cur_size = buffer_get_position (buffer ) - cur_doc_begin ;
15681569 enough_data = (buffer_get_position (buffer ) > max_cmd_size );
1569- if (enough_data ) {
1570- cur_size = buffer_get_position (buffer ) - cur_doc_begin ;
1571-
1572- /* This single document is too large for the command. */
1573- if (!idx ) {
1574- if (op == _INSERT ) {
1575- _set_document_too_large (cur_size , max_bson_size );
1576- } else {
1577- PyObject * DocumentTooLarge = _error ("DocumentTooLarge" );
1578- if (DocumentTooLarge ) {
1579- /*
1580- * There's nothing intelligent we can say
1581- * about size for update and delete.
1582- */
1583- PyErr_Format (
1584- DocumentTooLarge ,
1585- "%s command document too large" ,
1586- (op == _UPDATE ) ? "update" : "delete" );
1587- Py_DECREF (DocumentTooLarge );
1588- }
1570+ /* This single document is too large for the command. */
1571+ if (cur_size > max_cmd_size ) {
1572+ if (op == _INSERT ) {
1573+ _set_document_too_large (cur_size , max_bson_size );
1574+ } else {
1575+ PyObject * DocumentTooLarge = _error ("DocumentTooLarge" );
1576+ if (DocumentTooLarge ) {
1577+ /*
1578+ * There's nothing intelligent we can say
1579+ * about size for update and delete.
1580+ */
1581+ PyErr_Format (
1582+ DocumentTooLarge ,
1583+ "%s command document too large" ,
1584+ (op == _UPDATE ) ? "update" : "delete" );
1585+ Py_DECREF (DocumentTooLarge );
15891586 }
1590- goto fail ;
15911587 }
1588+ goto fail ;
1589+ }
1590+ if (enough_data ) {
15921591 /*
15931592 * Roll the existing buffer back to the beginning
15941593 * of the last document encoded.
0 commit comments