Open scoofy opened 2 years ago
I realized the issue is a PyMongo 3.x -> 4 problem.
GridFS changes disable_md5 parameter is removed Removed the disable_md5 option for GridFSBucket and GridFS. GridFS no longer generates checksums. Applications that desire a file digest should implement it outside GridFS and store it with other file metadata. For example:
import hashlib my_db = MongoClient().test fs = GridFSBucket(my_db) grid_in = fs.open_upload_stream("test_file") file_data = b'...' sha356 = hashlib.sha256(file_data).hexdigest() grid_in.write(file_data) grid_in.sha356 = sha356 # Set the custom 'sha356' field grid_in.close() Note that for large files, the checksum may need to be computed in chunks to avoid the excessive memory needed to load the entire file at once.
I upgraded to python 3.9 and i've run into some problems. When running:
mongo.send_file(filename)
Running tests, when I'm grabbing an image file from my mongo database, it seems to not be returning an MD5 in the fileobj, which causes an error here:
this seems to throw an error with werkzeug/http.py
TypeError: argument of type 'NoneType' is not iterable
I'm not exactly sure if this is the fault of flask-pymongo, or why i'm getting the error. But when i remove the set_etag line, it works just fine. The werkzeug file has a type hint that the etag must be a str, so it seems that you may want to turn a None instance into an empty string before running that function.