-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix course_id not present bug #5855
Conversation
WalkthroughThe changes in the Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
app/controllers/submissions_controller.rb (1)
114-122
: Improved error handling and data consistency checksThe changes address the "course_id not present" bug and improve data consistency checks. However, there are a few points to consider:
The
course
variable usage in line 121 is ambiguous. It's not clear if this is the samecourse
from line 115 or a different one. Consider using a different variable name or moving theSeries.find
logic into the first conditional block to clarify the relationship.There's no error handling for
Course.find
andSeries.find
. These could raiseActiveRecord::RecordNotFound
if the records don't exist. Consider usingfind_by
instead or add error handling to prevent potential crashes.Consider refactoring the code to address these issues:
if para[:course_id].present? course = Course.find_by(id: para[:course_id]) if course.nil? render json: { status: 'failed', errors: 'Course not found' }, status: :not_found return end para.delete(:course_id) if course.subscribed_members.exclude?(current_user) if para[:series_id].present? series = Series.find_by(id: para[:series_id]) if series.nil? render json: { status: 'failed', errors: 'Series not found' }, status: :not_found return end para.delete(:series_id) if course.series.exclude?(series) end endThis refactoring improves error handling and clarifies the relationship between
course
andseries
.
This pull request fixes broken code when course is
nil
. I also restructured the conditionals to improve readability.