Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mongoengine/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion tests/fields/test_file_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import tempfile
import unittest
import warnings
from io import BytesIO

import gridfs
Expand Down Expand Up @@ -69,7 +70,9 @@ class PutFile(Document):
== "<GridFSProxy: hello (%s)>" % 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()

Expand Down