-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.5.6
-
Component/s: None
-
None
-
Environment:Ubuntu 10.4, x86-64
-
ALL
See comments on (closed) PYTHON-152
findandmodify() raises pymongo.errors.OperationFailure when there are no matches:
File "build/bdist.linux-x86_64/egg/pymongo/database.py", line 294, in command
pymongo.errors.OperationFailure: command SON([('findandmodify', 'my_queue'), ('sort',
), ('query', {'started': {'$exists': False}}), ('update', {'$set': {'started': 1280965374}})]) failed: No matching object found
According to the mongodb documentation for findandmodify:
"This command can be used to atomically modify a document (at most one) and return it."
This implies that findandmodify() behaves much like the find() command--it is perfectly acceptable to not have a match at all.
Such behavior makes perfect sense. I do not believe it should constitute a command failure simply because there are no matches.
No matches should return an empty result, not raise a command failure exception.
IMO, command failure, should be when it finds a match but fails to make the modification, or some other actual but unexpected condition occurs.
This is a very common use case--a consumer pulling things off a queue. When the queue is empty, it shouldn't be generating an exception, just returning empty. It yields much nicer code.
- is related to
-
PYTHON-170 add findAndModify helper method
- Closed