@@ -93,10 +93,11 @@ def convert_to_entity(document, object_type, conventions, nested_object_types=No
9393 metadata = document .pop ("@metadata" )
9494 original_metadata = metadata .copy ()
9595 type_from_metadata = conventions .try_get_type_from_metadata (metadata )
96+ entity = _DynamicStructure (** document )
9697 object_from_metadata = None
9798 if type_from_metadata is not None :
9899 object_from_metadata = Utils .import_class (type_from_metadata )
99- entity = _DynamicStructure ( ** document )
100+
100101 if object_from_metadata is None :
101102 if object_type is not None :
102103 entity .__class__ = object_type
@@ -108,7 +109,9 @@ def convert_to_entity(document, object_type, conventions, nested_object_types=No
108109 entity .__class__ = object_from_metadata
109110 # Checking the class for initialize
110111 entity_initialize_dict = Utils .make_initialize_dict (document , entity .__class__ .__init__ )
111- entity .__init__ (** entity_initialize_dict )
112+
113+ entity = entity .__class__ (** entity_initialize_dict )
114+
112115 if nested_object_types :
113116 for key in nested_object_types :
114117 attr = getattr (entity , key )
@@ -134,8 +137,8 @@ def make_initialize_dict(document, entity_init):
134137 return document
135138
136139 entity_initialize_dict = {}
137- args , __ , __ , defaults = inspect .getargspec (entity_init )
138- if (len (args ) - 1 ) != len (document ):
140+ args , __ , keywords , defaults = inspect .getargspec (entity_init )
141+ if (len (args ) - 1 ) > len (document ):
139142 remainder = len (args )
140143 if defaults :
141144 remainder -= len (defaults )
@@ -144,7 +147,12 @@ def make_initialize_dict(document, entity_init):
144147 for i in range (remainder , len (args )):
145148 entity_initialize_dict [args [i ]] = document .get (args [i ], defaults [i - remainder ])
146149 else :
147- entity_initialize_dict = document
150+ if keywords == "kwargs" :
151+ entity_initialize_dict = document
152+ else :
153+ for key in document :
154+ if key in args :
155+ entity_initialize_dict [key ] = document [key ]
148156
149157 return entity_initialize_dict
150158
@@ -196,7 +204,7 @@ def numeric_to_lucene_syntax(value):
196204
197205 python_version = sys .version_info .major
198206
199- if (python_version > 2 and value > sys .maxsize and isinstance (value ,int )) \
207+ if (python_version > 2 and value > sys .maxsize and isinstance (value , int )) \
200208 or python_version <= 2 and isinstance (value , long ):
201209 value = "Lx{0}" .format (int (value ))
202210
0 commit comments