Skip to content

Commit

Permalink
replaced pymongo 'remove' with delete_many or delete_one internally
Browse files Browse the repository at this point in the history
  • Loading branch information
dill0wn committed Jun 28, 2024
1 parent e9d3c31 commit cd49eb4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 0 additions & 4 deletions ming/mim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ming/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions ming/tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})
Expand Down

0 comments on commit cd49eb4

Please sign in to comment.