Skip to content

Commit

Permalink
removed warnings from pymongo
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Nov 25, 2015
1 parent eb5b6ff commit 96e67ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/quorum/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,11 +1486,12 @@ class that does not inherit from the entity class.
def _increment(cls, name):
_name = cls._name() + ":" + name
db = mongodb.get_db()
value = db.counters.find_and_modify(
query = {
value = mongodb._store_find_and_modify(
db.counters,
{
"_id" : _name
},
update = {
{
"$inc" : {
"seq" : 1
}
Expand Down Expand Up @@ -1659,8 +1660,8 @@ def save(self, validate = True):
# retrieves the reference to the store object to be used and
# uses it to store the current model data
store = self._get_store()
if is_new: self._id = store.insert(model); self.apply(model)
else: store.update({"_id" : model["_id"]}, {"$set" : _model})
if is_new: self._id = mongodb._store_insert(store, model); self.apply(model)
else: mongodb._store_update(store, {"_id" : model["_id"]}, {"$set" : _model})

# calls the post save event handlers in order to be able to
# execute appropriate post operations
Expand Down
12 changes: 12 additions & 0 deletions src/quorum/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ def is_mongo(obj):
def is_new():
return int(pymongo.version[0]) >= 3 if pymongo else False

def _store_insert(store, *args, **kwargs):
if is_new(): store.insert_one(*args, **kwargs)
else: store.insert(*args, **kwargs)

def _store_update(store, *args, **kwargs):
if is_new(): store.update_one(*args, **kwargs)
else: store.update(*args, **kwargs)

def _store_find_and_modify(store, *args, **kwargs):
if is_new(): store.find_one_and_update(*args, **kwargs)
else: store.find_and_modify(*args, **kwargs)

def _get_connection(url):
global connection
if pymongo == None: raise exceptions.ModuleNotFound("pymongo")
Expand Down

0 comments on commit 96e67ee

Please sign in to comment.