Merged
Conversation
OpenAPI ChangesShow/hide ## Changes for v0.yaml:Unexpected changes? Ensure your branch is up-to-date with |
Comment on lines
+67
to
+70
| user = self.context["user"] | ||
| run_id = validated_data["run_id"] | ||
| run = models.CourseRun.objects.filter(id=run_id).first() | ||
|
|
There was a problem hiding this comment.
Bug: The create method in CourseRunEnrollmentSerializer accesses validated_data["run_id"], but the serializer doesn't declare a run_id field, which will cause a KeyError on enrollment creation.
Severity: CRITICAL
Suggested Fix
Add run_id = serializers.IntegerField(write_only=True) to the CourseRunEnrollmentSerializer class definition and include "run_id" in the Meta.fields list. This will align the v3 serializer with the behavior of the v1 and v2 versions.
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/v3/courses.py#L67-L70
Potential issue: The `create` method in the v3 `CourseRunEnrollmentSerializer` accesses
`validated_data["run_id"]` to create a new enrollment. However, the serializer itself
does not declare a `run_id` field, nor is it included in the `Meta.fields` list. When a
POST request is made to the `/api/v3/enrollments/` endpoint, the Django Rest Framework
will not include `run_id` in the `validated_data` dictionary because it's not a defined
field. This will cause the `create` method to fail with a `KeyError` for every
enrollment creation attempt, breaking this core functionality.
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.
Nathan Levesque