Skip to content

Fix AssertionError when creating a course via the web UI#1520

Merged
inducer merged 1 commit into
inducer:mainfrom
polds:fix/set-up-new-course-repo-assert
Jul 10, 2026
Merged

Fix AssertionError when creating a course via the web UI#1520
inducer merged 1 commit into
inducer:mainfrom
polds:fix/set-up-new-course-repo-assert

Conversation

@polds

@polds polds commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Problem

Creating a course through Set up new course fails with an AssertionError, even though the content validates and the course is actually created. The user sees:

Course content validated, creation succeeded.
Course creation failed: AssertionError:

…and then a 500 when opening the new course.

Traceback:

File "course/versioning.py", line 324, in set_up_new_course
    assert repo is not None
AssertionError

Cause

set_up_new_course initializes a local repo = None and closes it on both the success (else) and failure (except) paths. But git_clone_and_create_course opens its own repo via Repo.init(...) and never returns it, so the caller's repo stays None. On the success path, else: assert repo is not None therefore always fires — after create_course has already validated content and written the Course row. The clone's file handles also leak, since the intended repo.close() never receives a real repo.

Fix

Return the initialized repo from git_clone_and_create_course and assign it in the caller, so the existing close() logic on both branches works as intended. Two-line change plus a return annotation; no behavior change beyond closing the repo as was already intended.

Testing

  • python -m py_compile course/versioning.py passes.
  • Verified by reasoning through both paths: on success repo is now the real repo and is closed; on failure before the assignment, repo is None and the if repo is not None guard still holds.

set_up_new_course initializes a local `repo = None` and closes it on both the
success and failure paths, but git_clone_and_create_course never returned the
repo it opened. On the success path `repo` was therefore still None and the
`else: assert repo is not None` always fired -- raising AssertionError *after*
the course had already been created (content validated, DB row written), which
surfaces to the user as "creation succeeded" immediately followed by "creation
failed: AssertionError" and a 500 on the new course page. The repo's file
handles also leaked.

Return the initialized repo from git_clone_and_create_course and assign it in
the caller, so the existing close() logic on both branches works as intended.
@inducer inducer force-pushed the fix/set-up-new-course-repo-assert branch from 5e54fe6 to e59b232 Compare July 10, 2026 15:22
@inducer inducer enabled auto-merge (rebase) July 10, 2026 15:23
@inducer

inducer commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Thanks! LGTM, in it goes. Sorry about the delay.

@inducer inducer merged commit 4cf8bcc into inducer:main Jul 10, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants