diff --git a/mongoengine/fields.py b/mongoengine/fields.py index 37d5070a0..7b84acf58 100644 --- a/mongoengine/fields.py +++ b/mongoengine/fields.py @@ -1702,6 +1702,11 @@ def __getattr__(self, name): return getattr(obj, name) raise AttributeError + @property + def content_type(self): + # PyMongo deprecated content_type in favor of the GridFS contentType field. + return self.__getattr__("contentType") + def __get__(self, instance, value): return self diff --git a/tests/fields/test_file_field.py b/tests/fields/test_file_field.py index 43bb0fdbf..e53cbf1c7 100644 --- a/tests/fields/test_file_field.py +++ b/tests/fields/test_file_field.py @@ -2,6 +2,7 @@ import os import tempfile import unittest +import warnings from io import BytesIO import gridfs @@ -69,7 +70,9 @@ class PutFile(Document): == "" % result.the_file.grid_id ) assert result.the_file.read() == text - assert result.the_file.content_type == content_type + with warnings.catch_warnings(): + warnings.simplefilter("error", DeprecationWarning) + assert result.the_file.content_type == content_type result.the_file.delete() # Remove file from GridFS PutFile.objects.delete()