Skip to content

Commit d0b7099

Browse files
committed
Properly handle non-existing documents in Document.load() by returning None.
--HG-- extra : convert_revision : svn%3A7a298fb0-333a-0410-83e7-658617cd9cf3/trunk%4095
1 parent 0836624 commit d0b7099

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

couchdb/schema.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,17 @@ def rev(self):
200200
rev = property(rev)
201201

202202
def load(cls, db, id):
203-
"""Load a specific document from the given database."""
204-
return cls.wrap(db.get(id))
203+
"""Load a specific document from the given database.
204+
205+
:param db: the `Database` object to retrieve the document from
206+
:param id: the document ID
207+
:return: the `Document` instance, or `None` if no document with the
208+
given ID was found
209+
"""
210+
doc = db.get(id)
211+
if doc is None:
212+
return None
213+
return cls.wrap(doc)
205214
load = classmethod(load)
206215

207216
def store(self, db):

0 commit comments

Comments
 (0)