Skip to content

Commit

Permalink
[Backend] Show serializer errors in validation (#4231)
Browse files Browse the repository at this point in the history
  • Loading branch information
gchhablani authored Nov 30, 2023
1 parent f31a7b0 commit 61b44d8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
38 changes: 23 additions & 15 deletions apps/challenges/challenge_config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ def get_value_from_field(data, base_location, field_name):
"duplicate_rank": "ERROR: Duplicate rank {} found in YAML data.",
"prize_amount_wrong": "ERROR: Invalid amount value {}. Amount should be in decimal format with three-letter currency code (e.g. 100.00USD, 500EUR, 1000INR).",
"prize_rank_wrong": "ERROR: Invalid rank value {}. Rank should be an integer.",
"challenge_metadata_schema_errors": "ERROR: Unable to serialize the challenge because of the following errors: {}.",
"evaluation_script_not_zip": "ERROR: Please pass in a zip file as evaluation script. If using the `evaluation_script` directory (recommended), it should be `evaluation_script.zip`.",
}


Expand Down Expand Up @@ -503,24 +505,30 @@ def validate_submission_guidelines_file(self):
def validate_evaluation_script_file(self):
evaluation_script = self.yaml_file_data.get("evaluation_script")
if evaluation_script:
evaluation_script_path = join(
self.challenge_config_location, evaluation_script
)
# Check for evaluation script file in extracted zip folder
if isfile(evaluation_script_path):
self.challenge_evaluation_script_file = (
read_file_data_as_content_file(
evaluation_script_path, "rb", evaluation_script_path
)
)
self.files[
"challenge_evaluation_script_file"
] = self.challenge_evaluation_script_file
else:
if not evaluation_script.endswith('.zip'):
message = self.error_messages_dict.get(
"missing_evaluation_script"
"evaluation_script_not_zip"
)
self.error_messages.append(message)
else:
evaluation_script_path = join(
self.challenge_config_location, evaluation_script
)
# Check for evaluation script file in extracted zip folder
if isfile(evaluation_script_path):
self.challenge_evaluation_script_file = (
read_file_data_as_content_file(
evaluation_script_path, "rb", evaluation_script_path
)
)
self.files[
"challenge_evaluation_script_file"
] = self.challenge_evaluation_script_file
else:
message = self.error_messages_dict.get(
"missing_evaluation_script"
)
self.error_messages.append(message)
else:
message = self.error_messages_dict.get(
"missing_evaluation_script_key"
Expand Down
22 changes: 11 additions & 11 deletions apps/challenges/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3940,7 +3940,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):
if serializer.is_valid():
serializer.save()
else:
error_messages = serializer.errors
error_messages = f"leaderboard {data['id']} :{str(serializer.errors)}"
raise RuntimeError()
leaderboard_ids[
str(data["id"])
Expand Down Expand Up @@ -3980,7 +3980,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):
if serializer.is_valid():
serializer.save()
else:
error_messages = serializer.errors
error_messages = f"challenge phase {data['id']} :{str(serializer.errors)}"
raise RuntimeError()
challenge_phase_ids[
str(data["id"])
Expand All @@ -3998,7 +3998,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):
if serializer.is_valid():
serializer.save()
else:
error_messages = serializer.errors
error_messages = f"dataset split {data['id']} :{str(serializer.errors)}"
raise RuntimeError()
dataset_split_ids[
str(data["id"])
Expand Down Expand Up @@ -4055,7 +4055,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):
if serializer.is_valid():
serializer.save()
else:
error_messages = serializer.errors
error_messages = f"challenge phase split (phase:{data['challenge_phase_id']}, leaderboard:{data['leaderboard_id']}, dataset split: {data['dataset_split_id']}):{str(serializer.errors)}"
raise RuntimeError()

zip_config = ChallengeConfiguration.objects.get(
Expand Down Expand Up @@ -4118,7 +4118,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):

except: # noqa: E722
response_data = {
"error": "Error in creating challenge. Please check the yaml configuration!"
"error": f"Error in creating challenge: {error_messages}. Please check the yaml configuration!"
}
if error_messages:
response_data["error_message"] = json.dumps(error_messages)
Expand Down Expand Up @@ -4167,7 +4167,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):
if serializer.is_valid():
serializer.save()
else:
error_messages = serializer.errors
error_messages = f"challenge :{str(serializer.errors)}"
raise RuntimeError()
challenge = serializer.instance

Expand Down Expand Up @@ -4213,7 +4213,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):
serializer.save()
leaderboard_ids[str(data["id"])] = serializer.instance.pk
else:
error_messages = serializer.errors
error_messages = f"leaderboard update {(data['id'])} :{str(serializer.errors)}"
raise RuntimeError()

# Updating ChallengePhase objects
Expand Down Expand Up @@ -4278,7 +4278,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):
str(data["id"])
] = serializer.instance.pk
else:
error_messages = serializer.errors
error_messages = f"challenge phase update {(data['id'])} :{str(serializer.errors)}"
raise RuntimeError()

# Updating DatasetSplit objects
Expand All @@ -4305,7 +4305,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):
serializer.save()
dataset_split_ids[str(data["id"])] = serializer.instance.pk
else:
error_messages = serializer.errors
error_messages = f"dataset split update {(data['id'])} :{str(serializer.errors)}"
raise RuntimeError()

# Update ChallengePhaseSplit objects
Expand Down Expand Up @@ -4366,7 +4366,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):
if serializer.is_valid():
serializer.save()
else:
error_messages = serializer.errors
error_messages = f"challenge phase split update (phase:{data['challenge_phase_id']}, leaderboard:{data['leaderboard_id']}, dataset split: {data['dataset_split_id']}):{str(serializer.errors)}"
raise RuntimeError()

response_data = {
Expand All @@ -4377,7 +4377,7 @@ def create_or_update_github_challenge(request, challenge_host_team_pk):
return Response(response_data, status=status.HTTP_200_OK)
except: # noqa: E722
response_data = {
"error": "Error in creating challenge. Please check the yaml configuration!"
"error": f"Error in creating challenge: {error_messages}. Please check the yaml configuration!"
}
if error_messages:
response_data["error_message"] = json.dumps(error_messages)
Expand Down

0 comments on commit 61b44d8

Please sign in to comment.