Commit 9c4a9d8f by Jay Zoldak

Make code safe for unicode course ids

parent 65997d0f
......@@ -159,8 +159,9 @@ def perform_delegate_email_batches(entry_id, course_id, task_input, action_name)
# Perfunctory check, since expansion is made for convenience of other task
# code that doesn't need the entry_id.
if course_id != entry.course_id:
format_msg = "Course id conflict: explicit value {} does not match task value {}"
raise ValueError(format_msg.format(course_id, entry.course_id))
format_msg = u"Course id conflict: explicit value {} does not match task value {}"
log.warning("Task %s: %s", task_id, format_msg.format(course_id, entry.course_id))
raise ValueError("Course id conflict: explicit value does not match task value")
# Fetch the CourseEmail.
email_id = task_input['email_id']
......@@ -186,8 +187,9 @@ def perform_delegate_email_batches(entry_id, course_id, task_input, action_name)
# Sanity check that course for email_obj matches that of the task referencing it.
if course_id != email_obj.course_id:
format_msg = "Course id conflict: explicit value {} does not match email value {}"
raise ValueError(format_msg.format(course_id, email_obj.course_id))
format_msg = u"Course id conflict: explicit value {} does not match email value {}"
log.warning("Task %s: %s", task_id, format_msg.format(course_id, entry.course_id))
raise ValueError("Course id conflict: explicit value does not match email value")
# Fetch the course object.
try:
......@@ -219,7 +221,7 @@ def perform_delegate_email_batches(entry_id, course_id, task_input, action_name)
recipient_qset = _get_recipient_queryset(user_id, to_option, course_id, course.location)
recipient_fields = ['profile__name', 'email']
log.info("Task %s: Preparing to queue subtasks for sending emails for course %s, email %s, to_option %s",
log.info(u"Task %s: Preparing to queue subtasks for sending emails for course %s, email %s, to_option %s",
task_id, course_id, email_id, to_option)
progress = queue_subtasks_for_query(
......@@ -374,7 +376,7 @@ def _get_source_address(course_id, course_title):
invalid_chars = re.compile(r"[^\w.-]")
course_num = invalid_chars.sub('_', course_num)
from_addr = '"{0}" Course Staff <{1}-{2}>'.format(course_title_no_quotes, course_num, settings.BULK_EMAIL_DEFAULT_FROM_EMAIL)
from_addr = u'"{0}" Course Staff <{1}-{2}>'.format(course_title_no_quotes, course_num, settings.BULK_EMAIL_DEFAULT_FROM_EMAIL)
return from_addr
......
......@@ -181,7 +181,7 @@ def run_main_task(entry_id, task_fcn, action_name):
task_input = json.loads(entry.task_input)
# construct log message:
fmt = 'task "{task_id}": course "{course_id}" input "{task_input}"'
fmt = u'task "{task_id}": course "{course_id}" input "{task_input}"'
task_info_string = fmt.format(task_id=task_id, course_id=course_id, task_input=task_input)
TASK_LOG.info('Starting update (nothing %s yet): %s', action_name, task_info_string)
......@@ -190,7 +190,7 @@ def run_main_task(entry_id, task_fcn, action_name):
# that is running.
request_task_id = _get_current_task().request.id
if task_id != request_task_id:
fmt = 'Requested task did not match actual task "{actual_id}": {task_info}'
fmt = u'Requested task did not match actual task "{actual_id}": {task_info}'
message = fmt.format(actual_id=request_task_id, task_info=task_info_string)
TASK_LOG.error(message)
raise ValueError(message)
......@@ -416,15 +416,15 @@ def rescore_problem_module_state(xmodule_instance_args, module_descriptor, stude
if 'success' not in result:
# don't consider these fatal, but false means that the individual call didn't complete:
TASK_LOG.warning(u"error processing rescore call for course {course}, problem {loc} and student {student}: "
"unexpected response {msg}".format(msg=result, course=course_id, loc=module_state_key, student=student))
u"unexpected response {msg}".format(msg=result, course=course_id, loc=module_state_key, student=student))
return UPDATE_STATUS_FAILED
elif result['success'] not in ['correct', 'incorrect']:
TASK_LOG.warning(u"error processing rescore call for course {course}, problem {loc} and student {student}: "
"{msg}".format(msg=result['success'], course=course_id, loc=module_state_key, student=student))
u"{msg}".format(msg=result['success'], course=course_id, loc=module_state_key, student=student))
return UPDATE_STATUS_FAILED
else:
TASK_LOG.debug(u"successfully processed rescore call for course {course}, problem {loc} and student {student}: "
"{msg}".format(msg=result['success'], course=course_id, loc=module_state_key, student=student))
u"{msg}".format(msg=result['success'], course=course_id, loc=module_state_key, student=student))
return UPDATE_STATUS_SUCCEEDED
......@@ -558,7 +558,7 @@ def push_grades_to_s3(_xmodule_instance_args, _entry_id, course_id, _task_input,
grades_store = GradesStore.from_config()
grades_store.store_rows(
course_id,
"{}_grade_report_{}.csv".format(course_id_prefix, timestamp_str),
u"{}_grade_report_{}.csv".format(course_id_prefix, timestamp_str),
rows
)
......@@ -566,7 +566,7 @@ def push_grades_to_s3(_xmodule_instance_args, _entry_id, course_id, _task_input,
if len(err_rows) > 1:
grades_store.store_rows(
course_id,
"{}_grade_report_{}_err.csv".format(course_id_prefix, timestamp_str),
u"{}_grade_report_{}_err.csv".format(course_id_prefix, timestamp_str),
err_rows
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment