Improved API CRUD POST and PATCH handeling of data validation errors.
This commit is contained in:
@@ -569,9 +569,18 @@ async def patch_obj(
|
|||||||
if run_safety_check:
|
if run_safety_check:
|
||||||
log.info('Running safety check by default')
|
log.info('Running safety check by default')
|
||||||
base_name = obj_type_li[obj_name]['base_name']
|
base_name = obj_type_li[obj_name]['base_name']
|
||||||
obj_model = base_name(**crud.data_list) # .dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
try:
|
||||||
|
obj_model = base_name(**crud.data_list)
|
||||||
|
except Exception as e:
|
||||||
|
log.error('An unknown exception happened. Returning False.')
|
||||||
|
log.exception('**** *** ** * ### BEGIN ### Exception Happened: Returning False * ** *** ****')
|
||||||
|
log.warning(json.dumps(crud.data_list, indent=4))
|
||||||
|
return mk_resp(data=False, status_code=400, response=commons.response, status_message='There was likely a validation error. Returned False.')
|
||||||
|
else:
|
||||||
|
log.info('Successfully updated the object model.')
|
||||||
|
pass
|
||||||
log.debug(obj_model)
|
log.debug(obj_model)
|
||||||
# obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset, exclude=exclude)
|
|
||||||
obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset, include=field_list)
|
obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset, include=field_list)
|
||||||
log.debug(obj_dict)
|
log.debug(obj_dict)
|
||||||
crud_data = obj_dict
|
crud_data = obj_dict
|
||||||
@@ -713,16 +722,17 @@ async def post_obj(
|
|||||||
log.info('Running safety check by default')
|
log.info('Running safety check by default')
|
||||||
base_name = obj_type_li[obj_name]['base_name']
|
base_name = obj_type_li[obj_name]['base_name']
|
||||||
try:
|
try:
|
||||||
obj_model = base_name(**crud.data_list) # .dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
obj_model = base_name(**crud.data_list)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error('An unknown exception happened. Returning False.')
|
log.error('An unknown exception happened. Returning False.')
|
||||||
log.exception('**** *** ** * ### BEGIN ### Exception Happened: Returning False * ** *** ****')
|
log.exception('**** *** ** * ### BEGIN ### Exception Happened: Returning False * ** *** ****')
|
||||||
|
log.warning(json.dumps(crud.data_list, indent=4))
|
||||||
return mk_resp(data=False, status_code=400, response=commons.response, status_message='There was likely a validation error. Returned False.')
|
return mk_resp(data=False, status_code=400, response=commons.response, status_message='There was likely a validation error. Returned False.')
|
||||||
else:
|
else:
|
||||||
log.info('Successfully created the object model.')
|
log.info('Successfully created the object model.')
|
||||||
pass
|
pass
|
||||||
log.debug(obj_model)
|
log.debug(obj_model)
|
||||||
# obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset, exclude=exclude)
|
|
||||||
obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset, include=field_list)
|
obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset, include=field_list)
|
||||||
log.debug(obj_dict)
|
log.debug(obj_dict)
|
||||||
crud_data = obj_dict
|
crud_data = obj_dict
|
||||||
|
|||||||
Reference in New Issue
Block a user