1414
1515log = logging .getLogger (__name__ )
1616
17+
1718def annotate_doc_failure (func ):
1819 '''Decorator to wrap a session operation so that any pymongo errors raised
1920 will note the document that caused the failure
@@ -30,7 +31,7 @@ def wrapper(self, doc, *args, **kwargs):
3031 return update_wrapper (wrapper , func )
3132
3233
33- class Session ( object ) :
34+ class Session :
3435 _registry = {}
3536 _datastores = {}
3637
@@ -152,15 +153,13 @@ def _prep_save(self, doc, validate):
152153 return data
153154
154155 @annotate_doc_failure
155- def save (self , doc , state = None , ** kwargs ):
156- # args was meant to be the list of changed fields
157- # but actually we ended up checking the differences here
156+ def save (self , doc , * args , state = None , ** kwargs ):
158157 data = self ._prep_save (doc , kwargs .pop ('validate' , True ))
159- if state is not None and state .original_document :
160- if state is not None :
161- args = tuple ( set (( k for k , v in
162- doc_to_set (state . original_document )
163- ^ doc_to_set ( data ))))
158+ if not args and state is not None and state .original_document :
159+ args = tuple ( set (( k for k , v in
160+ doc_to_set ( state . original_document )
161+ ^ doc_to_set (data ))) )
162+ if args :
164163 values = dict ((arg , data [arg ]) for arg in args )
165164 result = self ._impl (doc ).update (
166165 dict (_id = doc ._id ), {'$set' : values }, ** fix_write_concern (kwargs ))
0 commit comments