Release 1.165.4 - #3945
Merged
Merged
Release 1.165.4#3945
Conversation
…3934) Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Chris Chudzicki <christopher.chudzicki@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
OpenAPI ChangesShow/hide changesUnexpected changes? Ensure your branch is up-to-date with |
|
|
||
| class LineSerializer(serializers.ModelSerializer): | ||
| product = serializers.SerializerMethodField() | ||
| product = ProductSerializer(read_only=True) |
Contributor
There was a problem hiding this comment.
Bug: The ProductPurchasableObjectField.to_representation method does not handle None values, causing a crash when serializing an order line for a deleted product.
Severity: HIGH
Suggested Fix
Add a null check at the beginning of the ProductPurchasableObjectField.to_representation() method. If the input value is None, the method should return None or an empty representation to prevent the InvalidPurchasableObjectTypeError exception.
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: ecommerce/serializers/__init__.py#L422
Potential issue: The `LineSerializer` was changed to use
`ProductSerializer(read_only=True)`. This serializer includes a `purchasable_object`
field handled by `ProductPurchasableObjectField`. If the underlying purchasable object
(e.g., a `CourseRun`) has been deleted from the database, the `GenericForeignKey` for it
will resolve to `None`. The `to_representation` method in
`ProductPurchasableObjectField` does not handle this `None` case. It fails all
`isinstance` checks and raises an `InvalidPurchasableObjectTypeError`. This will cause
API endpoints that serialize order history, such as `/api/v0/orders/history/`, to crash
for any user whose order contains a product associated with a deleted courseware item.
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.
annagav
James Kachel
cp-at-mit
Chris Chudzicki