Basically, if the disk get out of space (let say free space is 2KB) for saving with a python script, lets say, a 1MB file, the following will happen:
1- gridfs will first save the fs.files document. As it is only a few bytes, it will succeed.
2- gridfs will try to save fs.chunks, but it will fail because the disk is out of space.
3-pymongo will raise an error, and that is the end.
4- the next time someone query for that hash/file, gridfs will find it on fs.files, then it will search for the chunks, but the chunks will not be there. gridfs will raise CorruptGridFile.
The fix would be to handle the error of out of space, and remove fs.files document, so the grid doesn't go into corrupt state for that file.
root@db26f5ffc59d:/myapp# python -c "import sys; print(sys.version)"
2.7.14 (default, Mar 14 2018, 18:16:04)
[GCC 6.3.0 20170516]
root@db26f5ffc59d:/myapp# python -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"
3.6.1
True