55from typing import ClassVar , Type , Union
66
77from aenum import StrEnum
8- from marshmallow import fields , Schema
8+ from marshmallow import fields , Schema , post_dump
99from marshmallow_dataclass import dataclass
1010from semver import VersionInfo
1111
@@ -27,7 +27,10 @@ def _deserialize(self, value, attr, data, **kwargs):
2727 if not value :
2828 return None
2929 elif isinstance (value , int ):
30- return datetime .fromtimestamp (value )
30+ try :
31+ return datetime .fromtimestamp (value )
32+ except Exception as ex :
33+ raise ValueError (f'{ ex .args [0 ]} , value = { value } , attr = { attr } ' )
3134 else :
3235 return super ()._deserialize (value , attr , data , ** kwargs )
3336
@@ -45,7 +48,10 @@ def _deserialize(self, value, attr, data, **kwargs):
4548 if not value :
4649 return None
4750 elif isinstance (value , int ):
48- return datetime .fromtimestamp (value / 1000000000 )
51+ try :
52+ return datetime .fromtimestamp (value / 1000000000 )
53+ except Exception as ex :
54+ raise ValueError (f'{ ex .args [0 ]} , value = { value } , attr = { attr } ' )
4955 else :
5056 return super ()._deserialize (value , attr , data , ** kwargs )
5157
@@ -65,7 +71,7 @@ def _deserialize(self, value, attr, data, **kwargs):
6571 elif isinstance (value , int ):
6672 try :
6773 return datetime .fromtimestamp (value / 1000 )
68- except ValueError as ex :
74+ except Exception as ex :
6975 raise ValueError (f'{ ex .args [0 ]} , value = { value } , attr = { attr } ' )
7076 else :
7177 return super ()._deserialize (value , attr , data , ** kwargs )
@@ -84,7 +90,10 @@ def _deserialize(self, value, attr, data, **kwargs):
8490 if not value :
8591 return None
8692 elif isinstance (value , str ):
87- return IPv4Interface (value )
93+ try :
94+ return IPv4Interface (value )
95+ except Exception as ex :
96+ raise ValueError (f'{ ex .args [0 ]} , value = { value } , attr = { attr } ' )
8897 else :
8998 return super ()._deserialize (value , attr , data , ** kwargs )
9099
@@ -104,7 +113,10 @@ def _deserialize(self, value, attr, data, **kwargs):
104113 elif isinstance (value , str ):
105114 if '_' in value :
106115 value = value .split ('_' )[0 ]
107- return VersionInfo .parse (value )
116+ try :
117+ return VersionInfo .parse (value )
118+ except Exception as ex :
119+ raise ValueError (f'{ ex .args [0 ]} , value = { value } , attr = { attr } ' )
108120 else :
109121 return super ()._deserialize (value , attr , data , ** kwargs )
110122
@@ -146,6 +158,17 @@ def name(self) -> str:
146158 def id (self ) -> str :
147159 raise BanyanError ('not implemented' )
148160
161+ # noinspection PyUnusedLocal
162+ @post_dump
163+ def _remove_nulls (self , data , many , ** kwargs ):
164+ new_data = dict ()
165+ for key , val in data .items ():
166+ if isinstance (val , dict ):
167+ new_data [key ] = self ._remove_nulls (val , False , ** kwargs )
168+ elif val is not None :
169+ new_data [key ] = val
170+ return new_data
171+
149172
150173ResourceOrName = Union [Resource , str ]
151174
0 commit comments