|
1 | | -from dateutil import parser as datetimeparser |
2 | 1 | import traceback |
3 | 2 | import json |
| 3 | +import copy |
| 4 | +from dateutil import parser as datetimeparser |
4 | 5 | from urllib import parse |
5 | 6 |
|
6 | 7 | from cinp.common import URI |
@@ -66,9 +67,9 @@ def _dictConverter( value ): |
66 | 67 |
|
67 | 68 | MAP_TYPE_CONVERTER = { |
68 | 69 | 'NoneType': lambda a: None, |
69 | | - 'str': str, |
70 | | - 'int': str, |
71 | | - 'float': str, |
| 70 | + 'str': lambda a: a, |
| 71 | + 'int': lambda a: a, |
| 72 | + 'float': lambda a: a, |
72 | 73 | 'bool': lambda a: True if a else False, |
73 | 74 | 'datetime': lambda a: a.isoformat(), |
74 | 75 | 'timedelta': lambda a: a.total_seconds(), |
@@ -249,7 +250,7 @@ def _fromPython( self, paramater, python_value ): |
249 | 250 | if not isinstance( python_value, dict ): |
250 | 251 | raise ValueError( 'Map must be dict' ) |
251 | 252 |
|
252 | | - result = python_value.copy() |
| 253 | + result = copy.deepcopy( python_value ) |
253 | 254 | _fromPythonMap( result ) |
254 | 255 |
|
255 | 256 | return result |
@@ -595,11 +596,11 @@ def _asDict( self, converter, target_object ): # yes this is a bit of a hack, w |
595 | 596 | result = {} |
596 | 597 | for field_name in self.field_map: |
597 | 598 | try: |
598 | | - result[ field_name ] = converter.fromPython( self.field_map[ field_name ], getattr( target_object, field_name ) ) # TODO: disguinsh between the AttributeError oflooking up the field, and any errors pulling the field value might cause |
| 599 | + result[ field_name ] = converter.fromPython( self.field_map[ field_name ], getattr( target_object, field_name ) ) # TODO: disguinsh between the AttributeError of looking up the field, and any errors pulling the field value might cause |
599 | 600 | except ValueError as e: |
600 | 601 | raise ValueError( 'Error with "{0}": "{1}"'.format( field_name, str( e ) ) ) |
601 | 602 | except AttributeError: |
602 | | - raise ServerError( 'target_object missing field "{0}"'.format( field_name ) ) # yes, internal server error, target_object comes from inside the house |
| 603 | + raise ServerError( 'target_object("{0}") missing field "{1}"'.format( target_object.__class__.__name__, field_name ) ) # yes, internal server error, target_object comes from inside the house |
603 | 604 |
|
604 | 605 | return result |
605 | 606 |
|
@@ -712,10 +713,10 @@ def create( self, converter, transaction, data ): |
712 | 713 | error_map[ field_name ] = 'Invalid Value "{0}"'.format( str( e ) ) |
713 | 714 |
|
714 | 715 | except KeyError: |
715 | | - if field.required: |
716 | | - error_map[ field_name ] = 'Required Field' |
717 | | - else: |
| 716 | + if field.default is not None: |
718 | 717 | value_map[ field_name ] = field.default |
| 718 | + elif field.required: |
| 719 | + error_map[ field_name ] = 'Required Field' |
719 | 720 |
|
720 | 721 | if error_map != {}: |
721 | 722 | raise InvalidRequest( data=error_map ) |
|
0 commit comments