Skip to content

PYTHON-6183 Reject non-string filename in GridFS get_version - #3237

Merged
aclark4life merged 8 commits into
mongodb:mainfrom
aclark4life:PYTHON-6183
Nov 19, 2026
Merged

aclark4life merged 8 commits into
mongodb:mainfrom
aclark4life:PYTHON-6183

Conversation

@aclark4life

@aclark4life aclark4life commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

PYTHON-6183

Changes in this PR

GridFS.get_version and GridFS.get_last_version now reject a filename that is not a string or None with a TypeError.

Test Plan

  • Added test_get_version_invalid_filename to test/asynchronous/test_gridfs.py.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

@aclark4life
aclark4life marked this pull request as ready for review November 19, 2026 01:43
@aclark4life
aclark4life requested a review from a team as a code owner November 19, 2026 01:43
@aclark4life
aclark4life requested review from sleepyStick and a balanced review from Copilot November 19, 2026 01:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The changelog entry does not follow the required format: it must begin with “Fixed,” use past tense, and use Sphinx roles for method and exception references.

1 open issue
What changed in this PR

This PR tightens GridFS filename validation so get_version and get_last_version reject values other than strings or None with a TypeError.

Changes:

  • Adds filename validation to synchronous and asynchronous GridFS implementations.
  • Adds regression tests for dictionary and list filenames.
  • Documents the behavior change in the changelog.
File Description
test/​test_gridfs.py Adds synchronous invalid-filename regression tests.
test/​asynchronous/​test_gridfs.py Adds asynchronous invalid-filename regression tests.
gridfs/​synchronous/​grid_file.py Validates filenames before constructing the query.
gridfs/​asynchronous/​grid_file.py Applies the same validation to asynchronous retrieval.
doc/​changelog.rst Documents the stricter filename validation.

Review effort: Balanced

Comment thread doc/changelog.rst Outdated
Comment on lines +15 to +17
- GridFS ``get_version`` and ``get_last_version`` now raise ``TypeError`` when
``filename`` is not a string or ``None``, instead of treating a dict as query
criteria (`PYTHON-6183`_).
Comment thread doc/changelog.rst
and treated a dict as query criteria. They now raise :exc:`TypeError`
(`PYTHON-6183`_).

.. _PYTHON-6183: https://jira.mongodb.org/browse/PYTHON-6183

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit but can this link be added after the python-6262 link?

``-3``, version ``1`` is the same as version ``-2``, and
version ``2`` is the same as version ``-1``.

Raises :class:`~gridfs.errors.NoFile` if no such version of

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add that a type error can be raised if filename is the wrong type?

Comment thread gridfs/asynchronous/grid_file.py Outdated
:class:`~pymongo.client_session.AsyncClientSession`
:param kwargs: find files by custom metadata.

.. versionchanged:: 4.20.1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be added to get_last_version (like around line 267) as well?

@aclark4life
aclark4life merged commit ed20791 into mongodb:main Nov 19, 2026
50 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants