Skip to content

Commit

Permalink
Use UUID4 as unique value for section value
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickMTonne committed Feb 22, 2024
1 parent 382f0bf commit 1994962
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions manage_sections/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
import logging
import re
import uuid

from canvas_api.helpers import courses as canvas_api_helper_courses
from canvas_api.helpers import enrollments as canvas_api_helper_enrollments
Expand Down Expand Up @@ -221,32 +222,24 @@ def create_db_section(course_instance: CourseInstance, section_name: str):
sync_to_canvas = 1,
title = section_name.strip(),
short_title = section_name.strip(),
section = str(uuid.uuid4())
)
db_course_section.save()
except Exception as e:
logger.exception(
f'Unexpected error while creating section for '
f'parent_course_instance_id:{course_instance.course_instance_id}',
extra={'error': e},
)
raise

# Then backfill the `section` column with the course_instance_id of the new record
try:
db_course_section.section = str(db_course_section.course_instance_id)
db_course_section.save()
except Exception as e:
logger.exception(
f'Unexpected error setting section value for '
f'parent_course_instance_id:{course_instance.course_instance_id}',
f'parent_course_instance_id: {course_instance.course_instance_id}',
extra={'error': e},
)
raise

logger.info(
f'Successfully created section for '
f'parent_course_instance_id:{course_instance.course_instance_id}',
extra={'course_instance_id': db_course_section.course_instance_id},
f'parent_course_instance_id: {course_instance.course_instance_id}',
extra={
'course_instance_id': db_course_section.course_instance_id,
'title': db_course_section.title,
}
)

return db_course_section

0 comments on commit 1994962

Please sign in to comment.