Skip to content

Commit d5fcd50

Browse files
author
Renan Chagas
committed
fix alredy exists mapping erro when both types has the same name (different modules/packages)
1 parent b02c6d6 commit d5fcd50

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

mapper/object_mapper.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
"""
33
Copyright (C) 2015, marazt. All rights reserved.
44
"""
5-
from mapper.object_mapper_exception import ObjectMapperException
5+
from enum import Enum
6+
from inspect import getmembers, isroutine, isclass
7+
68
from mapper.casedict import CaseDict
7-
from inspect import getmembers, isroutine
9+
from mapper.object_mapper_exception import ObjectMapperException
10+
811

912
class ObjectMapper(object):
1013
"""
@@ -91,8 +94,8 @@ def create_map(self, type_from, type_to, mapping=None):
9194
9295
:return: None
9396
"""
94-
key_from = type_from.__name__
95-
key_to = type_to.__name__
97+
key_from = type_from
98+
key_to = type_to
9699

97100
if mapping is None:
98101
mapping = {}
@@ -165,7 +168,17 @@ def not_excluded(s):
165168

166169
else:
167170
# try find property with the same name in the source
168-
if prop in from_props:
171+
if prop not in from_props:
172+
continue
173+
174+
prop_to_type = type(from_props[prop])
175+
176+
if isclass(prop_to_type) and \
177+
not issubclass(prop_to_type, Enum) and \
178+
prop_to_type is not type(None) and \
179+
not __builtins__.get(type(from_props[prop]).__name__):
180+
self.map(from_props[prop], key_to, allow_none=allow_none)
181+
else:
169182
setattr(inst, prop, from_props[prop])
170183
# case when target attribute is not mapped (can be extended)
171184
else:

0 commit comments

Comments
 (0)