Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

Commit

Permalink
Fix DBRefField not handing null values
Browse files Browse the repository at this point in the history
  • Loading branch information
amitnabarro committed Oct 10, 2017
1 parent 54644a7 commit de7dc82
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tbone/data/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def __call__(self, value):

def __repr__(self):
if self._bound:
return '<%s instance in model %s>' % (self.__class__.__qualname__, self.container_model_class.__name__)
return '<%s instance in model %s>' % (self.__class__.__qualname__, self.container_model.__name__)
return '<%s instance>' % self.__class__.__qualname__

@property
Expand Down
4 changes: 4 additions & 0 deletions tbone/data/fields/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def __init__(self, model_class, **kwargs):
raise TypeError("DBRefField: Expected a model of the type '{}'.".format(model_class.__name__))

def _import(self, value):
if value is None:
return None
if isinstance(value, self.model_class):
if not hasattr(value, '_id'):
raise ValueError(self._errors['missing_id'])
Expand All @@ -68,6 +70,8 @@ def _import(self, value):
raise ValueError(self._errors['to_python'])

def _export(self, value):
if value is None:
return None
if isinstance(value, self.model_class):
if not hasattr(value, '_id'):
raise ValueError(self._errors['missing_id'])
Expand Down

0 comments on commit de7dc82

Please sign in to comment.