Skip to content

Commit

Permalink
fix: raise ValidationError if user is not enrolled in given run
Browse files Browse the repository at this point in the history
  • Loading branch information
marslanabdulrauf committed Jan 24, 2025
1 parent ac651cf commit e649553
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions courses/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ def defer_enrollment(
.order_by("-created_on")
.first()
)
if not from_enrollment:
raise ValidationError(
f"User is not enrolled in course run '{from_courseware_id}'" # noqa: EM102
)
if not force and not from_enrollment.active:
raise ValidationError(
f"Cannot defer from inactive enrollment (id: {from_enrollment.id}, run: {from_enrollment.run.courseware_id}, user: {user.email}). " # noqa: EM102
Expand Down

0 comments on commit e649553

Please sign in to comment.