From cd49eb4c4f26e13d0cd453c9cc9ca0d58fd1eed9 Mon Sep 17 00:00:00 2001 From: Dillon Walls Date: Fri, 28 Jun 2024 15:59:06 -0400 Subject: [PATCH] replaced pymongo 'remove' with delete_many or delete_one internally --- ming/mim.py | 4 ---- ming/session.py | 6 +++--- ming/tests/test_session.py | 8 ++++---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/ming/mim.py b/ming/mim.py index 3c619c9..44ac0da 100644 --- a/ming/mim.py +++ b/ming/mim.py @@ -553,10 +553,6 @@ def __remove(self, spec=None, **kwargs): self._data = new_data return result - def remove(self, spec=None, **kwargs): - warnings.warn('remove is now deprecated, please use delete_many or delete_one', DeprecationWarning, stacklevel=2) - self.__remove(spec, **kwargs) - def delete_one(self, filter, session=None): res = self.__remove(filter, multi=False) return DeleteResult(res, True) diff --git a/ming/session.py b/ming/session.py index 63d6ee3..418e715 100644 --- a/ming/session.py +++ b/ming/session.py @@ -90,13 +90,13 @@ def find(self, cls, *args, **kwargs): allow_extra=allow_extra, strip_extra=strip_extra) - def remove(self, cls, *args, **kwargs): + def remove(self, cls, filter={}, *args, **kwargs): fix_write_concern(kwargs) for kwarg in kwargs: if kwarg not in ('spec_or_id', 'w'): raise ValueError("Unexpected kwarg %s. Did you mean to pass a dict? If only sent kwargs, pymongo's remove()" " would've emptied the whole collection. Which we're pretty sure you don't want." % kwarg) - return self._impl(cls).remove(*args, **kwargs) + return self._impl(cls).delete_many(filter, *args, **kwargs) def find_by(self, cls, **kwargs): return self.find(cls, kwargs) @@ -185,7 +185,7 @@ def upsert(self, doc, spec_fields, **kwargs): @annotate_doc_failure def delete(self, doc): - return self._impl(doc).remove({'_id':doc._id}) + return self._impl(doc).delete_one({'_id':doc._id}) def _set(self, doc, key_parts, value): if len(key_parts) == 0: diff --git a/ming/tests/test_session.py b/ming/tests/test_session.py index b891e4f..ad4c798 100644 --- a/ming/tests/test_session.py +++ b/ming/tests/test_session.py @@ -57,13 +57,13 @@ def test_base_session(self): dict(a=None, b=dict(a=None), _id=None, cc=dict(dd=None, ee=None))) sess.find(TestDoc, dict(a=5)) + impl.find_one.assert_called_with(dict(a=5)) sess.remove(TestDoc, dict(a=5)) + impl.delete_many.assert_called_with(dict(a=5)) sess.update_partial(TestDoc, dict(a=5), dict(b=6), False) + impl.update_one.assert_called_with(dict(a=5), dict(b=6), False) - impl.find_one.assert_called_with(dict(a=5)) impl.find.assert_called_with(dict(a=5)) - impl.remove.assert_called_with(dict(a=5)) - impl.update_one.assert_called_with(dict(a=5), dict(b=6), False) doc = TestDoc({}) sess.save(doc) @@ -74,7 +74,7 @@ def test_base_session(self): sess.insert(doc) impl.insert_one.assert_called_with(doc) sess.delete(doc) - impl.remove.assert_called_with(dict(_id=None)) + impl.delete_one.assert_called_with(dict(_id=None)) impl.reset_mock() doc = self.TestDocNoSchema({'_id':5, 'a':5})