Skip to content

PYTHON-6299 Reject non-string filename in GridFSBucket delete_by_name… - #3262

Open
MaddipatlaChetan24 wants to merge 1 commit into
mongodb:mainfrom
MaddipatlaChetan24:PYTHON-6299
Open

MaddipatlaChetan24 wants to merge 1 commit into
mongodb:mainfrom
MaddipatlaChetan24:PYTHON-6299

Conversation

@MaddipatlaChetan24

Copy link
Copy Markdown
Contributor

PYTHON-6299

Changes in this PR

GridFSBucket.delete_by_name and rename_by_name passed filename straight into the files query, so a dict was used as query criteria: delete_by_name({"$ne": None}) deleted every file in the bucket. This adds the same validate_string check that open_download_stream_by_name already does (and that PYTHON-6183 added to GridFS.get_version), and also validates new_filename in rename_by_name. Sync files regenerated with synchro.

Test Plan

Added test_delete_by_name_invalid_filename and test_rename_by_name_invalid_filename (async and sync). They check that a dict raises TypeError and that no file is deleted or renamed.

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).

AI disclosure: I used an AI assistant to help find this and draft the change. I reviewed every line, understand the fix, and will handle review myself.

… and rename_by_name

PYTHON-6183 made GridFS.get_version and get_last_version reject a
non-string filename, because a dict was used as query criteria.
GridFSBucket.delete_by_name and rename_by_name had the same problem:
delete_by_name({"$ne": None}) matched and deleted every file in the
bucket. Validate filename (and new_filename) the same way
open_download_stream_by_name already does.

This branch has not been deployed

No deployments
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.

1 participant