You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PyMongo deprecated the GridOut.contentType property and will remove it in PyMongo 5.0:
GridOut property 'contentType' is deprecated and will be removed in PyMongo 5.0
Although flask-admin's code reads data.content_type (snake_case), the underlying GridFS GridOut object still resolves this through the deprecated contentType accessor, so the DeprecationWarning fires on every read.
Flask-admin's test suite runs pytest with filterwarnings = ["error", ...], which promotes every warning to an error. PR #2918 added a default:GridOut property 'contentType' is deprecated...:DeprecationWarning entry to pyproject.toml, which downgrades this specific warning back to the default (print-once) behavior so the new MongoEngine test could pass. The warning itself is not silenced — it is just exempted from the strict-errors policy. This issue tracks the actual migration off the deprecated property.
flask_admin/contrib/mongoengine/view.py — api_file_view reads data.content_type where data = fs.get(...) is a raw GridOut
flask_admin/contrib/mongoengine/widgets.py — MongoFileInput reads field.data.content_type where field.data is a GridFSProxy
flask_admin/contrib/mongoengine/typefmt.py — grid_formatter reads value.content_type where value is a GridFSProxy/GridOut
Not affected
flask_admin/contrib/mongoengine/fields.py — this reads content_type from a Werkzeug FileStorage (the uploaded file) on the write path and passes it into GridFSProxy.put/replace. Not a GridOut attribute access; unrelated to the PyMongo deprecation.
Proposed approach
Two of the three read sites go through MongoEngine's GridFSProxy rather than raw PyMongo. Investigate whether MongoEngine already exposes (or plans to expose) a non-deprecated accessor; if so, use it directly. If not, fall back to reading the content type from the GridFS document's metadata dict (PyMongo's recommended location in 5.0) with a mimetypes.guess_type(filename) fallback when missing.
Centralize the lookup in a small helper (e.g. _gridfs_content_type(data)) so all three read-side call sites share one implementation and the raw-GridOut site and GridFSProxy sites stay consistent.
Remove the default:GridOut property 'contentType'... entry from pyproject.toml once the migration lands and verify the suite still passes under filterwarnings = ["error", ...].
PyMongo deprecation notice: GridOut contentType → removed in 5.0
Disclosure: I drafted this issue with help from Claude Code while reviewing feedback on PR #2918; the affected call sites were verified manually against the current master.
Context
PyMongo deprecated the
GridOut.contentTypeproperty and will remove it in PyMongo 5.0:Although flask-admin's code reads
data.content_type(snake_case), the underlying GridFSGridOutobject still resolves this through the deprecatedcontentTypeaccessor, so theDeprecationWarningfires on every read.Flask-admin's test suite runs pytest with
filterwarnings = ["error", ...], which promotes every warning to an error. PR #2918 added adefault:GridOut property 'contentType' is deprecated...:DeprecationWarningentry topyproject.toml, which downgrades this specific warning back to the default (print-once) behavior so the new MongoEngine test could pass. The warning itself is not silenced — it is just exempted from the strict-errors policy. This issue tracks the actual migration off the deprecated property.Affected call sites (read path —
GridOut/GridFSProxy)flask_admin/contrib/mongoengine/view.py—api_file_viewreadsdata.content_typewheredata = fs.get(...)is a rawGridOutflask_admin/contrib/mongoengine/widgets.py—MongoFileInputreadsfield.data.content_typewherefield.datais aGridFSProxyflask_admin/contrib/mongoengine/typefmt.py—grid_formatterreadsvalue.content_typewherevalueis aGridFSProxy/GridOutNot affected
flask_admin/contrib/mongoengine/fields.py— this readscontent_typefrom a WerkzeugFileStorage(the uploaded file) on the write path and passes it intoGridFSProxy.put/replace. Not aGridOutattribute access; unrelated to the PyMongo deprecation.Proposed approach
GridFSProxyrather than raw PyMongo. Investigate whether MongoEngine already exposes (or plans to expose) a non-deprecated accessor; if so, use it directly. If not, fall back to reading the content type from the GridFS document'smetadatadict (PyMongo's recommended location in 5.0) with amimetypes.guess_type(filename)fallback when missing._gridfs_content_type(data)) so all three read-side call sites share one implementation and the raw-GridOutsite andGridFSProxysites stay consistent.default:GridOut property 'contentType'...entry frompyproject.tomlonce the migration lands and verify the suite still passes underfilterwarnings = ["error", ...].test_api_file_view_sets_content_disposition) still asserts the correctContent-Type(text/plain) after the migration.Out of scope
api_file_viewbeyond the content-type source.References
contentType→ removed in 5.0