Skip to content

Commit

Permalink
Merge pull request #24 from TurboGears/mim_save_no_id
Browse files Browse the repository at this point in the history
Use our __insert not pymongo parent _insert
  • Loading branch information
brondsem committed Jun 19, 2020
2 parents 3822601 + f053692 commit 7f96f10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ming/mim.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def save(self, doc, **kwargs):
warnings.warn('save is now deprecated, please use insert_one or replace_one', DeprecationWarning)
_id = doc.get('_id', ())
if _id == ():
return self._insert(doc)
return self.__insert(doc)
else:
self.__update({'_id':_id}, doc, upsert=True)
return _id
Expand Down
9 changes: 9 additions & 0 deletions ming/tests/test_mim.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,15 @@ def test_insert_manipulate_true(self):
self.bind.db.coll.insert(doc, manipulate=True)
self.assertEqual(doc, {'x': 1, '_id': sample_id})

def test_save_id(self):
doc = {'_id': bson.ObjectId(), 'x': 1}
self.bind.db.coll.save(doc)

def test_save_no_id(self):
doc = {'x': 1}
self.bind.db.coll.save(doc)
assert isinstance(doc['_id'], bson.ObjectId)

def test_unique_index_subdocument(self):
coll = self.bind.db.coll

Expand Down

0 comments on commit 7f96f10

Please sign in to comment.