@@ -244,15 +244,16 @@ def validate_attribute(value: Any, root_obj: Any, att_field: Field, path: str) -
244244 attribute_dot_path = path ,
245245 )
246246 )
247- elif isinstance (att_field , str ):
248- errs .append (
249- ValidationObjectError (
250- error_type = ErrorType .WARNING ,
251- target_obj = root_obj ,
252- attribute_dot_path = path ,
253- msg = f"Attribute '{ att_field } ' is a string but got value '{ value } '" ,
254- )
255- )
247+ elif is_primitive (att_field ) or not hasattr (att_field , "metadata" ):
248+ return errs
249+ # errs.append(
250+ # ValidationObjectError(
251+ # error_type=ErrorType.WARNING,
252+ # target_obj=root_obj,
253+ # attribute_dot_path=path,
254+ # msg=f"Attribute '{att_field}' is a string but got value '{value}'",
255+ # )
256+ # )
256257 elif not is_enum (value ): # sometimes enums values fails the validation
257258 try :
258259 min_length = att_field .metadata .get ("min_length" , None )
@@ -296,20 +297,30 @@ def validate_attribute(value: Any, root_obj: Any, att_field: Field, path: str) -
296297 attribute_dot_path = path ,
297298 )
298299 )
300+ elif min_occurs > 0 and not isinstance (value , list ):
301+ errs .append (
302+ ValidationObjectError (
303+ msg = f"Min occurs was { min_occurs } but found a single value : { value } " ,
304+ error_type = ErrorType .CRITICAL ,
305+ target_obj = root_obj ,
306+ attribute_dot_path = path ,
307+ )
308+ )
299309
300310 if min_inclusive is not None :
301311 potential_err = ValidationObjectError (
302- msg = f"Min occurs was { min_inclusive } but found { value } " ,
312+ msg = f"Min inclusive was { min_inclusive } but found { value } " ,
303313 error_type = ErrorType .CRITICAL ,
304314 target_obj = root_obj ,
305315 attribute_dot_path = path ,
306316 )
307- if isinstance (value , list ):
308- for val in value :
309- if (isinstance (val , str ) and len (val ) > min_inclusive ) or (
310- (isinstance (val , int ) or isinstance (val , float )) and val > min_inclusive
311- ):
312- errs .append (potential_err )
317+ if not isinstance (value , list ):
318+ value = [value ]
319+ for val in value :
320+ if (isinstance (val , str ) and len (val ) < min_inclusive ) or (
321+ (isinstance (val , int ) or isinstance (val , float )) and val < min_inclusive
322+ ):
323+ errs .append (potential_err )
313324
314325 if pattern is not None :
315326 if not isinstance (value , list ):
@@ -331,6 +342,7 @@ def validate_attribute(value: Any, root_obj: Any, att_field: Field, path: str) -
331342 )
332343 except Exception as e :
333344 print (f"Error while validating attribute '{ att_field } ' with value '{ value } ': { str (e )} for { path } " )
345+ print (f"att_field : { att_field } , is primitive : { is_primitive (att_field )} " )
334346 errs .append (
335347 ValidationObjectError (
336348 msg = f"Error while validating attribute '{ att_field } ' with value '{ value } ': { str (e )} " ,
@@ -340,6 +352,9 @@ def validate_attribute(value: Any, root_obj: Any, att_field: Field, path: str) -
340352 )
341353 )
342354 traceback .print_exc ()
355+
356+ # if isinstance(e, AttributeError):
357+
343358 exit (0 )
344359 return errs
345360
0 commit comments