Release 1.144.3#3447
Merged
Merged
Conversation
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[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
173
to
+177
|
|
||
| return ( | ||
| instance.first_unexpired_run is not None | ||
| and instance.first_unexpired_run.certificate_available_date is not None | ||
| and hasattr(instance, "verified_courserun_count") | ||
| and instance.verified_courserun_count > 0 |
There was a problem hiding this comment.
Bug: The get_certificate_available method relies on the verified_courserun_count annotation, which is not present when CourseSerializer is used outside the CourseViewSet, causing incorrect results.
Severity: MEDIUM
Suggested Fix
The logic for get_certificate_available should not depend on an annotation that is only applied in a specific viewset. Instead, it should directly query the related courseruns to determine if any have a verified enrollment mode. This will make the serializer's logic self-contained and reliable across all its usage contexts.
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/serializers/v2/courses.py#L173-L177
Potential issue: The `get_certificate_available` method in `CourseSerializer` was
updated to check for a `verified_courserun_count` attribute on the `Course` instance.
This attribute is only annotated onto the queryset within the `CourseViewSet`. However,
`CourseSerializer` is also instantiated directly in other parts of the codebase, such as
in `cms/models.py`. In these contexts, the `Course` instance lacks the
`verified_courserun_count` annotation. The `hasattr` check will fail, causing the method
to silently and incorrectly return `False` for `certificate_available`, leading to
incorrect data in API endpoints that consume the serializer outside the viewset.
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
Asad Ali