Repository navigation
feat!: use OpaqueKey scope IDs in the workbench runtime - #567
salman2013 wants to merge 1 commit into
Conversation
The workbench's ScenarioIdManager now generates OpaqueKey scope IDs instead of raw strings, matching what edx-platform has used for years: * usage IDs are BlockUsageLocators in a fake course per scenario, e.g. block-v1:workbench+a-little-html+run+type@html+block@d0.u0 * definition IDs are DefinitionLocators whose ObjectId is derived from the old scenario-based name, so they stay stable across reloads * aside IDs are AsideUsageKeyV2 / AsideDefinitionKeyV2 The key-value store serializes the usage keys held in children/parent fields to JSON and back, XBlockState derives scenario/tag from the keys, and the handler views parse the usage key from the URL (404 on invalid or unknown keys). BREAKING CHANGE: XBlocks running in the workbench now receive OpaqueKey instances for scope_ids.usage_id and scope_ids.def_id instead of strings. Part of openedx/XBlock#784 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Thanks for the pull request, @salman2013! 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. |
irfanuddinahmad
left a comment
There was a problem hiding this comment.
Non-blocking: maybe mention in the BREAKING CHANGE note that with reset_state_on_restart: False, state saved under the old string scope IDs won't be found anymore (the old rows just get orphaned).
| block_type=block_type, | ||
| block_id=f"{def_local_id}.u{next(id_seq)}", | ||
| ) | ||
| self._usages[usage_id] = def_id |
There was a problem hiding this comment.
Non-blocking, pre-existing: last_created_usage_id() sorts the keys, so it returns the highest locator rather than the most recent one (e.g. d9.u0 after d11.u0, or the wrong scenario). Since _usages is a dict, next(reversed(self._usages), None) would give the actual last one.
| try: | ||
| block = runtime.get_aside(aside_id) | ||
| except NoSuchUsage as ex: | ||
| block = runtime.get_aside(UsageKey.from_string(aside_id)) |
There was a problem hiding this comment.
Non-blocking: only the 404 paths are tested here. A small test that posts to a real aside's handler_url would cover the AsideUsageKeyV2 parsing on the success path.
Description
Part of the DEPR openedx/XBlock#784 (xblock-sdk task): update the workbench's XBlock runtime to use OpaqueKey scope IDs rather than raw string scope IDs.
edx-platform has used OpaqueKeys for scope IDs for years, but the workbench still generated strings like
a-little-html.html.d0.u0. Blocks therefore behaved differently in the workbench than in the platform, and the workbench would break once XBlock starts enforcing key types (openedx/XBlock#809).What changed
ScenarioIdManagernow generates keys:"a-little-html.html.d0.u0"BlockUsageLocator, e.g.block-v1:workbench+a-little-html+run+type@html+block@d0.u0"a-little-html.html.d0"DefinitionLocator, e.g.def-v1:<24 hex>+type@html"<id>.<aside_type>"AsideUsageKeyV2/AsideDefinitionKeyV2course-v1:workbench+<scenario>+run), so usage IDs stay unique across scenarios.Supporting changes:
WorkbenchDjangoKeyValueStore:children/parentvalues hold usage keys, which JSON can't encode. They're saved as strings and parsed back into keys when loaded.XBlockState.get_for_key: getsscenario/tagfrom the keys instead of splitting strings. Definition keys don't carry their scenario, so it's looked up throughScenarioIdManager.get_scenario(). No migration is needed.pyproject.toml/uv.lock:edx-opaque-keysis now a direct dependency.Breaking change
XBlocks running in the workbench now get OpaqueKey instances for
scope_ids.usage_idandscope_ids.def_idinstead of strings. Blocks that do string operations on them needstr(...).Testing
I tested the extracted XBlocks in the XBlock SDK workbench. The html, annotatable, poll question, and word cloud blocks load and render as expected.
Note:
Note: This PR was implemented with assistance from Claude Code (Opus 5.5), then manually reviewed and tested.