diff --git a/cms/djangoapps/cms_user_tasks/tasks.py b/cms/djangoapps/cms_user_tasks/tasks.py index 89d4e7a217..da05f48a6d 100644 --- a/cms/djangoapps/cms_user_tasks/tasks.py +++ b/cms/djangoapps/cms_user_tasks/tasks.py @@ -30,14 +30,12 @@ def send_task_complete_email(self, task_name, task_state_text, dest_addr, detail context = { 'task_name': task_name, 'task_status': task_state_text, - 'detail_url': detail_url + 'detail_url': detail_url, + 'olx_validation_errors': False } if olx_validation_text: try: - olx_validations = json.loads(olx_validation_text) - context['olx_validation_errors'] = True - context['error_summary'] = olx_validations.get('error_summary') - context['error_report'] = olx_validations.get('error_report') + context['olx_validation_errors'] = json.loads(olx_validation_text) except ValueError: # includes simplejson.decoder.JSONDecodeError LOGGER.error(f'Unable to parse CourseOlx validation text: {olx_validation_text}') diff --git a/cms/djangoapps/contentstore/tasks.py b/cms/djangoapps/contentstore/tasks.py index 8dc2352edd..25ed8596b7 100644 --- a/cms/djangoapps/contentstore/tasks.py +++ b/cms/djangoapps/contentstore/tasks.py @@ -684,21 +684,31 @@ def validate_course_olx(courselike_key, course_dir, status): LOGGER.exception(f'{log_prefix}: CourseOlx Could not be validated') return olx_is_valid + log_errors = len(errorstore.errors) > 0 + if log_errors: + log_errors_to_artifact(errorstore, status) + has_errors = errorstore.return_error(ErrorLevel.ERROR.value) if not has_errors: return olx_is_valid - errorstore.errors = [error for error in errorstore.errors if error.level_val == ErrorLevel.ERROR.value] - error_summary = report_error_summary(errorstore) - error_report = report_errors(errorstore) - message = json.dumps({ - 'error_summary': error_summary, - 'error_report': error_report, - }) - UserTaskArtifact.objects.create(status=status, name='OLX_VALIDATION_ERROR', text=message) LOGGER.error(f'{log_prefix}: CourseOlx validation failed') # TODO: Do not fail the task until we have some data about kinds of # olx validation failures. TNL-8151 - return olx_is_valid + + +def log_errors_to_artifact(errorstore, status): + """Log errors as a task artifact.""" + def get_error_by_type(error_type): + return [error for error in error_report if error.startswith(error_type)] + + error_summary = report_error_summary(errorstore) + error_report = report_errors(errorstore) + message = json.dumps({ + 'summary': error_summary, + 'errors': get_error_by_type(ErrorLevel.ERROR.name), + 'warnings': get_error_by_type(ErrorLevel.WARNING.name), + }) + UserTaskArtifact.objects.create(status=status, name='OLX_VALIDATION_ERROR', text=message) diff --git a/cms/templates/emails/user_task_complete_email.txt b/cms/templates/emails/user_task_complete_email.txt index 3cfd1fe014..afbd11982f 100644 --- a/cms/templates/emails/user_task_complete_email.txt +++ b/cms/templates/emails/user_task_complete_email.txt @@ -12,13 +12,16 @@ ${_("Your {task_name} task has completed with the status '{task_status}'. Sign i % if olx_validation_errors: -${_("Here are some validation errors we found with your course content.")} +${_("Here are some validations we found with your course content.")} - -% for error in error_report: - ${error} +${_("Errors:")} +% for error in olx_validation_errors.get('errors'): + * ${error} % endfor -% else: +${_("Warnings:")} +% for warning in olx_validation_errors.get('warnings'): + * ${warning} +% endfor % endif