Skip to content

Commit

Permalink
Fixed error that would occur when creation_action not specified. Also
Browse files Browse the repository at this point in the history
added additional validation for empty values. Made it more clear in error
messages what the acceptable values are for creation_action. Made creation
action validator case insensitive. Also normalized the case for creation
action within the trigger. Now always has the first letter capitalized.
  • Loading branch information
DerekFurstPitt committed Sep 28, 2023
1 parent 2dc0808 commit af8ac17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/schema/schema_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1907,8 +1907,8 @@ def get_upload_datasets(property_key, normalized_type, user_token, existing_data
def set_activity_creation_action(property_key, normalized_type, user_token, existing_data_dict, new_data_dict):
if 'normalized_entity_type' not in new_data_dict:
raise KeyError("Missing 'normalized_entity_type' key in 'existing_data_dict' during calling 'set_activity_creation_action()' trigger method.")
if new_data_dict and new_data_dict['creation_action']:
return property_key, new_data_dict['creation_action']
if new_data_dict and new_data_dict.get('creation_action'):
return property_key, new_data_dict['creation_action'].title()
return property_key, f"Create {new_data_dict['normalized_entity_type']} Activity"


Expand Down
9 changes: 6 additions & 3 deletions src/schema/schema_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,12 @@ def validate_publication_date(property_key, normalized_entity_type, request, exi
The json data in request body, already after the regular validations
"""
def validate_creation_action(property_key, normalized_entity_type, request, existing_data_dict, new_data_dict):
creation_action = new_data_dict[property_key]
if creation_action and creation_action not in ["Central Process", "Lab Process", "Multi-Assay Split"]:
raise ValueError(f"Invalid {property_key} value")
accepted_creation_action_values = ["central process", "lab process", "multi-assay split"]
creation_action = new_data_dict[property_key].lower()
if creation_action and creation_action not in accepted_creation_action_values:
raise ValueError("Invalid {} value. Accepted values are: {}".format(property_key, ", ".join(accepted_creation_action_values)))
if creation_action == '':
raise ValueError(f"The property {property_key} cannot be empty, when specified.")


####################################################################################################
Expand Down

0 comments on commit af8ac17

Please sign in to comment.