feat: accept library_content_key on the v1 Xblock create payload (FC-0118)#38908
Conversation
…0118) The v1 `XblockViewSet` validates every request body against the strict `XblockSerializer`, which returns 400 on any unlisted top-level field. Studio's real create payload includes `library_content_key` when a course block is created by importing a component from a v2 library — `create_xblock_response` reads it to set the block's upstream reference — so the strict serializer must declare the field or it rejects the legitimate request. This unblocks migrating the frontend-app-authoring block-creation caller to the standardized `/api/contentstore/v1/xblock/` endpoint (ADR 0028). Adds a regression test asserting a create body carrying `library_content_key` reaches the handler instead of being rejected with a 400. Refs openedx/frontend-app-authoring#3127 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thanks for the pull request, @taimoor-ahmed-1! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Description
The v1
XblockViewSet(cms/djangoapps/contentstore/rest_api/v1/views/xblock.py)gates every write behind
@validate_request_with_serializer, which validates therequest body against
XblockSerializer. That serializer subclassesStrictSerializer, so any top-level field not declared on the serializer causesa 400 before the handler runs.
Studio's real block-creation payload includes
library_content_keywhen acourse block is created by importing a component from a v2 library. The create
handler already reads it:
But because
library_content_keywas not declared onXblockSerializer, thestrict serializer rejects that payload with a 400 before the handler is reached.
This makes the v1 create endpoint unusable for the (common) library-import path.
This PR declares
library_content_keyas an optional field onXblockSerializerso the strict validation accepts the legitimate create payload.
Why this matters now
This unblocks migrating
frontend-app-authoring's block-creation caller(
createCourseXblock) from the legacy/xblock/route to the standardized/api/contentstore/v1/xblock/endpoint as part of the FC-0118 downstream-consumermigration — see openedx/frontend-app-authoring#3127 (item #1, Xblock). Without
this field, migrating "add/import block" to v1 would break block creation.
Changes
cms/djangoapps/contentstore/rest_api/v0/serializers/xblock.py— declarelibrary_content_key = serializers.CharField(required=False, allow_null=True).cms/djangoapps/contentstore/rest_api/v1/views/tests/test_xblock_viewset.py—regression test asserting a create body carrying
library_content_keyreachescreate_xblock_response(200) instead of being rejected (400).Testing
XblockViewSetRoutingTest.test_create_accepts_library_content_key.pytest cms/djangoapps/contentstore/rest_api/v1/views/tests/test_xblock_viewset.py.Notes
feat/axim-api_improvements(the FC-0118 standardizationfeature branch where the v1
XblockViewSetlives; not yet onmaster).it only stops the strict serializer from rejecting a field the create handler
already consumes.
type,courseKey) are not addedhere because they are redundant/ignored by the handler; the frontend migration
PR drops them instead of sending dead data.