Fixing dereferencing when the dereferenced-document wasn't found.

This commit is contained in:
Karim Allah 2011-09-25 18:58:40 +02:00
parent adb7bbeea0
commit c081aca794

View File

@ -10,6 +10,7 @@ import pymongo
import pymongo.objectid
import operator
from functools import partial
from bson.dbref import DBRef
class NotRegistered(Exception):
@ -97,6 +98,9 @@ class BaseField(object):
# Get value from document instance if available, if not use default
value = instance._data.get(self.name)
if isinstance(value, DBRef):
raise ValueError("Can't dereference from the given DBRef (%s)" % str(value))
if value is None:
value = self.default
# Allow callable default values