twisted / txmongo

asynchronous python driver for mongo
https://txmongo.readthedocs.io
Apache License 2.0
338 stars 102 forks source link

TxMongo should correctly reject too large documents #208

Open IlyaSkriblovsky opened 7 years ago

IlyaSkriblovsky commented 7 years ago

PyMongo raises DocumentTooLarge in all situations when document that is larger than max_bson_size is sent to DB.

TxMongo fails with two different invalid errors:

  1. when insert() is called with too large document, it fails with OperationFailure
  2. when insert_one() is called, it fails with AutoReconnect, probably because MongoDB closes the connection when TxMongo tries to send too large document with new-style command-based API.

Size checking should be done on TxMongo's size at least in following places:

  1. Database.command (covers all new-style *_one/_many methods)
  2. Old-style insert(), update(), etc.
  3. Bulk ops
psi29a commented 7 years ago

Nice find and I agree that the check on the TxMongo side would reduce overhead on MongoDB itself and save us extra calls.

IlyaSkriblovsky commented 7 years ago

reduce overhead on MongoDB itself and save us extra calls

and extra reconnects in case of new-style insert_one() :)