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

Commit

Permalink
Only convert container types
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Jan 6, 2017
1 parent 4765472 commit 42c0e7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion yorm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
from .bases import Container, Converter, Mappable

__project__ = 'YORM'
__version__ = '1.2b3'
__version__ = '1.2b4'
18 changes: 10 additions & 8 deletions yorm/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,17 @@ def load(self):

# Add missing attributes
for name, converter in attrs2.items():
if hasattr(self._obj, name):
existing_attr = getattr(self._obj, name)
if not isinstance(existing_attr, converter):
log.trace("Converting attribute %r to %r", name, converter)
value = converter.create_default()
setattr(self._obj, name, value)
self._remap(value, self)
existing_attr = getattr(self._obj, name, None)
if existing_attr:
if issubclass(converter, Container):
if not isinstance(existing_attr, converter):
msg = "Converting container attribute %r to %r"
log.trace(msg, name, converter)
value = converter.create_default()
setattr(self._obj, name, value)
self._remap(value, self)
else:
value = converter.to_value(None)
value = converter.create_default()
msg = "Default value for missing object attribute: %s = %r"
log.warning(msg, name, value)
setattr(self._obj, name, value)
Expand Down

0 comments on commit 42c0e7e

Please sign in to comment.