Fix: course creation - prevent comparison error for books with None for shelf_section - #1331
Open
ascholerChemeketa wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent a crash on the course creation page when sorting book shelf_section values that may be None, by introducing a fallback section label.
Changes:
- Default missing
shelf_sectionvalues to"Misc"when building thesectionslist for the course creation page. - Apply the same
sectionsbehavior in both the GET handler and the error-rendering path of the POST handler.
Comments suppressed due to low confidence (1)
bases/rsptx/admin_server_api/routers/instructor.py:1450
- Same issue in the error-handling path:
sectionsuses the "Misc" fallback, butcourse_listretainsshelf_section=None, so those books won’t render under any section in the template (it comparescourse.shelf_section == section). Normalizeshelf_sectionincourse_listbefore computingsections.
course_list = [c.dict() for c in course_list if c.for_classes]
sections = sorted({c["shelf_section"] or "Misc" for c in course_list})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
1322
to
+1323
| course_list = [c.dict() for c in course_list if c.for_classes] | ||
| sections = sorted({c["shelf_section"] for c in course_list}) | ||
| sections = sorted({c["shelf_section"] or "Misc" for c in course_list}) |
Member
|
Seems like providing a default for the shelf_section and/or making a pass through Also we ought to file issues against those books that don't provide a shelf section so the author can remedy that. I must have "fixed" all those in production a while ago. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have a bunch of books in my dev library where shelf_section is None. That crashes the sort code when creating a new course. This fixes the course creation page to handle those.