@@ -86,7 +86,7 @@ def _check_pattern_match(self, value, name, operation, pattern):
8686 .format (operation , name , pattern ))
8787 pass
8888
89- def _to_string (self , value , name , operation ):
89+ def _to_string (self , value , name , operation , message ):
9090 """
9191 Transforms value into string if is only a number, if is other type
9292 it will raises an Exception
@@ -97,13 +97,14 @@ def _to_string(self, value, name, operation):
9797 :type feature: str
9898 :param operation: operation to inform the error
9999 :type operation: str
100+ :param message: message to inform the error
101+ :type message: str
100102 """
101103 if not isinstance (value , bool ) and isinstance (value , Number ):
102104 self ._logger .warning ('{}: {} {} is not of type string, converting.'
103105 .format (operation , name , value ))
104106 return str (value )
105- raise InputException ('{}: {} {} has to be of type string or object Key.'
106- .format (operation , name , value ))
107+ raise InputException ('{}: {} {} {}' .format (operation , name , value , message ))
107108
108109 def _validate_matching_key (self , matching_key ):
109110 """
@@ -120,12 +121,8 @@ def _validate_matching_key(self, matching_key):
120121 if isinstance (matching_key , six .string_types ):
121122 self ._check_not_empty (matching_key , 'matching_key' , 'get_treatment' )
122123 return matching_key
123- if not isinstance (matching_key , bool ) and isinstance (matching_key , Number ):
124- self ._logger .warning ('get_treatment: matching_key {} is not of type string, '
125- 'converting.' .format (matching_key ))
126- return str (matching_key )
127- raise InputException ('get_treatment: matching_key {} has to be of type string.'
128- .format (matching_key ))
124+ return self ._to_string (matching_key , 'matching_key' , 'get_treatment' ,
125+ 'has to be of type string.' )
129126 except InputException as e :
130127 raise InputException (e .message )
131128
@@ -143,12 +140,8 @@ def _validate_bucketing_key(self, bucketing_key):
143140 return None
144141 if isinstance (bucketing_key , six .string_types ):
145142 return bucketing_key
146- if not isinstance (bucketing_key , bool ) and isinstance (bucketing_key , Number ):
147- self ._logger .warning ('get_treatment: bucketing_key {} is not of type '
148- 'string, converting.' .format (bucketing_key ))
149- return str (bucketing_key )
150- raise InputException ('get_treatment: bucketing_key {} has to be of type string.'
151- .format (bucketing_key ))
143+ return self ._to_string (bucketing_key , 'bucketing_key' , 'get_treatment' ,
144+ 'has to be of type string.' )
152145 except InputException as e :
153146 raise InputException (e .message )
154147
@@ -169,7 +162,8 @@ def validate_key(self, key):
169162 if isinstance (key , six .string_types ):
170163 matching_key = key
171164 else :
172- matching_key = self ._to_string (key , 'key' , 'get_treatment' )
165+ matching_key = self ._to_string (key , 'key' , 'get_treatment' ,
166+ 'has to be of type string or object Key.' )
173167 bucketing_key = None
174168 return matching_key , bucketing_key
175169 except InputException as e :
@@ -202,11 +196,7 @@ def validate_track_key(self, key):
202196 self ._check_not_null (key , 'key' , 'track' )
203197 if isinstance (key , six .string_types ):
204198 return key
205- if not isinstance (key , bool ) and isinstance (key , Number ):
206- self ._logger .warning ('track: key {} is not of type string, converting.'
207- .format (key ))
208- return str (key )
209- self ._logger .error ('track: key {} has to be of type string.' .format (key ))
199+ return self ._to_string (key , 'key' , 'track' , 'has to be of type string.' )
210200 except InputException as e :
211201 self ._logger .error (e .message )
212202 return None
0 commit comments