diff --git a/apps/challenges/challenge_config_utils.py b/apps/challenges/challenge_config_utils.py index f048bb4e45..f1ac39da3e 100644 --- a/apps/challenges/challenge_config_utils.py +++ b/apps/challenges/challenge_config_utils.py @@ -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`.", } @@ -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" diff --git a/apps/challenges/views.py b/apps/challenges/views.py index ea96224c55..7427bd5dea 100644 --- a/apps/challenges/views.py +++ b/apps/challenges/views.py @@ -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"]) @@ -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"]) @@ -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"]) @@ -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( @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 = { @@ -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)