Skip to content

Commit 370ba42

Browse files
committed
Address review
1 parent e98c5af commit 370ba42

File tree

7 files changed

+16
-6
lines changed

7 files changed

+16
-6
lines changed

doc/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PyMongo 4.12 brings a number of changes including:
99
- Support for configuring DEK cache lifetime via the ``key_expiration_ms`` argument to
1010
:class:`~pymongo.encryption_options.AutoEncryptionOpts`.
1111
- Support for $lookup in CSFLE and QE supported on MongoDB 8.1+.
12+
- Added :meth:`gridfs.asynchronous.grid_file.AsyncGridFSBucket.delete_by_name` and :meth:`gridfs.grid_file.GridFSBucket.delete_by_name`
13+
for more performant deletion of a file with multiple revisions.
1214

1315
Issues Resolved
1416
...............

gridfs/asynchronous/grid_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ async def delete_by_name(
857857
"""
858858
_disallow_transactions(session)
859859
files = self._files.find({"filename": filename}, {"_id": 1}, session=session)
860-
file_ids = [file_id["_id"] async for file_id in files]
860+
file_ids = [file["_id"] async for file in files]
861861
res = await self._files.delete_many({"_id": {"$in": file_ids}}, session=session)
862862
await self._chunks.delete_many({"files_id": {"$in": file_ids}}, session=session)
863863
if not res.deleted_count:

gridfs/synchronous/grid_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ def delete_by_name(self, filename: str, session: Optional[ClientSession] = None)
851851
"""
852852
_disallow_transactions(session)
853853
files = self._files.find({"filename": filename}, {"_id": 1}, session=session)
854-
file_ids = [file_id["_id"] for file_id in files]
854+
file_ids = [file["_id"] for file in files]
855855
res = self._files.delete_many({"_id": {"$in": file_ids}}, session=session)
856856
self._chunks.delete_many({"files_id": {"$in": file_ids}}, session=session)
857857
if not res.deleted_count:

test/asynchronous/test_session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
from bson import DBRef
4747
from gridfs.asynchronous.grid_file import AsyncGridFS, AsyncGridFSBucket
48-
from pymongo import ASCENDING, AsyncMongoClient, monitoring
48+
from pymongo import ASCENDING, AsyncMongoClient, _csot, monitoring
4949
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
5050
from pymongo.asynchronous.cursor import AsyncCursor
5151
from pymongo.asynchronous.helpers import anext
@@ -458,6 +458,7 @@ async def test_cursor(self):
458458
f"{name} sent wrong lsid with {event.command_name}",
459459
)
460460

461+
@_csot.apply
461462
async def test_gridfs(self):
462463
client = self.client
463464
fs = AsyncGridFS(client.pymongo_test)
@@ -500,6 +501,7 @@ async def find_list(session=None):
500501
(fs.delete, [1], {}),
501502
)
502503

504+
@_csot.apply
503505
async def test_gridfs_bucket(self):
504506
client = self.client
505507
bucket = AsyncGridFSBucket(client.pymongo_test)
@@ -546,6 +548,7 @@ async def find(session=None):
546548
(bucket.delete, [2], {}),
547549
)
548550

551+
@_csot.apply
549552
async def test_gridfsbucket_cursor(self):
550553
client = self.client
551554
bucket = AsyncGridFSBucket(client.pymongo_test)

test/asynchronous/test_transactions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from bson import encode
3434
from bson.raw_bson import RawBSONDocument
35-
from pymongo import WriteConcern
35+
from pymongo import WriteConcern, _csot
3636
from pymongo.asynchronous import client_session
3737
from pymongo.asynchronous.client_session import TransactionOptions
3838
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
@@ -240,6 +240,7 @@ async def create_and_insert(session):
240240
self.assertEqual(ctx.exception.code, 48) # NamespaceExists
241241

242242
@async_client_context.require_transactions
243+
@_csot.apply
243244
async def test_gridfs_does_not_support_transactions(self):
244245
client = async_client_context.client
245246
db = client.pymongo_test

test/test_session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
from bson import DBRef
4747
from gridfs.synchronous.grid_file import GridFS, GridFSBucket
48-
from pymongo import ASCENDING, MongoClient, monitoring
48+
from pymongo import ASCENDING, MongoClient, _csot, monitoring
4949
from pymongo.common import _MAX_END_SESSIONS
5050
from pymongo.errors import ConfigurationError, InvalidOperation, OperationFailure
5151
from pymongo.operations import IndexModel, InsertOne, UpdateOne
@@ -458,6 +458,7 @@ def test_cursor(self):
458458
f"{name} sent wrong lsid with {event.command_name}",
459459
)
460460

461+
@_csot.apply
461462
def test_gridfs(self):
462463
client = self.client
463464
fs = GridFS(client.pymongo_test)
@@ -500,6 +501,7 @@ def find_list(session=None):
500501
(fs.delete, [1], {}),
501502
)
502503

504+
@_csot.apply
503505
def test_gridfs_bucket(self):
504506
client = self.client
505507
bucket = GridFSBucket(client.pymongo_test)
@@ -546,6 +548,7 @@ def find(session=None):
546548
(bucket.delete, [2], {}),
547549
)
548550

551+
@_csot.apply
549552
def test_gridfsbucket_cursor(self):
550553
client = self.client
551554
bucket = GridFSBucket(client.pymongo_test)

test/test_transactions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from bson import encode
3434
from bson.raw_bson import RawBSONDocument
35-
from pymongo import WriteConcern
35+
from pymongo import WriteConcern, _csot
3636
from pymongo.errors import (
3737
CollectionInvalid,
3838
ConfigurationError,
@@ -232,6 +232,7 @@ def create_and_insert(session):
232232
self.assertEqual(ctx.exception.code, 48) # NamespaceExists
233233

234234
@client_context.require_transactions
235+
@_csot.apply
235236
def test_gridfs_does_not_support_transactions(self):
236237
client = client_context.client
237238
db = client.pymongo_test

0 commit comments

Comments
 (0)