Closed
Conversation
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
OpenAPI ChangesShow/hide ## Changes for v0.yaml:Unexpected changes? Ensure your branch is up-to-date with |
Comment on lines
338
to
+348
| user = self.request.user | ||
| if qp.get("org_id"): | ||
| added_context["org_id"] = qp.get("org_id") | ||
| added_context["user_contracts"] = ( | ||
| ( | ||
| user.b2b_contracts.filter( | ||
| organization__pk=added_context["org_id"] | ||
| ) | ||
| .values_list("id", flat=True) | ||
| .all() | ||
| ) |
There was a problem hiding this comment.
Bug: The retrieve_by_readable_id view action does not handle the DoesNotExist exception, causing a 500 error if a course is not found.
Severity: MEDIUM
Suggested Fix
Use get_object_or_404 from django.shortcuts instead of .get(). This will automatically handle the DoesNotExist case by returning a 404 Not Found response. Alternatively, wrap the .get() call in a try...except Course.DoesNotExist block and manually return a Response with a 404 status.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: courses/views/v2/__init__.py#L336-L348
Potential issue: The `retrieve_by_readable_id` view action uses
`self.get_queryset().get(readable_id=readable_id)` to fetch a course. If a `readable_id`
is provided that does not match any existing course, the `.get()` method will raise a
`Course.DoesNotExist` exception. Since this exception is not handled within the view, it
will propagate up and result in a 500 Internal Server Error response for the client,
instead of a more appropriate 404 Not Found.
Did we get this right? 👍 / 👎 to inform future reviews.
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.
James Kachel
Nathan Levesque
renovate[bot]