Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-453

GridFS.new_file fails to raise FileExists with a manual _id

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 2.4.2
    • None
    • None

    Description

      When using GridFS.new_file with a manually-specified, pre-existing _id, and safe=True on the database connection, FileExists is not raised. This happens when trying to create the same file with non-empty contents.

      db = Connection('localhost', safe=True).some_db
      f = GridFS(db).new_file(_id='some id')
      f.write('some content')
      f.close() # file is created correctly
      f = GridFS(db).new_file(_id='some id') # does not raise FileExists
      f.write('some content')
      f.close() # raises DuplicateKeyError instead of FileExists

      Reason:

      GridIn.close() calls GridIn.__flush(). This in turn eventually calls self._chunks.insert(chunk). With safe=True on the connection, the chunk insert raises DuplicateKeyError, which is not caught.

      This will also happen on the f.write(content) call if the content causes GridIn's buffer to exceed the chunk size (because it will flush and raise the same DuplicateKeyError).

      Attachments

        Activity

          People

            ross@mongodb.com Ross Lawley
            tdterry Travis Terry
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: