Skip to content

refactor: Simplify backcompat definitions for url_name, et al#37845

Merged
kdmccormick merged 2 commits intomasterfrom
kdmccormick/url-name
Mar 24, 2026
Merged

refactor: Simplify backcompat definitions for url_name, et al#37845
kdmccormick merged 2 commits intomasterfrom
kdmccormick/url-name

Conversation

@kdmccormick
Copy link
Member

@kdmccormick kdmccormick commented Jan 7, 2026

Description & Supporting Info

XModuleMixin and CourseOverview both provided some backcompat names for some XBlock key attributes. Due to refactors in edx-platform and improvements to the XBlock API that have happened over the years, we can now simplify these backcompat mappings. The new mappings (old -> new) are:

  • .course_id -> .context_key
  • .location -> .usage_key
  • .url_name -> .usage_key.block_id
  • .category -> .usage_key.block_type

These are the ways we would like developers to access these attributes going forward, so it's important that we use them in XModuleMixin and CourseOverview to set a good example.

We also remove the block_metadata_utils.url_name_for_block method, as it was unnecessarily indirect for such a simple operation. There are no remaining references to it in edx-platform.

Note: It is technically correct to go through .scope_ids for these fields, but it's harder to read. Under the hood, the XBlock API indeed uses .scope_ids:
https://github.com/openedx/XBlock/blob/v5.3.0/xblock/core.py#L422-L446

Testing instructions

None

Deadline

Soon, as this influences openedx/xblocks-contrib#128

@kdmccormick
Copy link
Member Author

@farhan , could you please review this, and then incorporate it into openedx/xblocks-contrib#128 ?

@farhan
Copy link
Contributor

farhan commented Feb 24, 2026

@farhan , could you please review this, and then incorporate it into openedx/xblocks-contrib#128 ?

Sure, I will, added in the queue

@farhan farhan moved this to 👀 In review in Aximprovements Team Feb 24, 2026
@farhan
Copy link
Contributor

farhan commented Mar 9, 2026

@kdmccormick tests cases are failing on this PR.
Please rebase it to latest.

@kdmccormick kdmccormick force-pushed the kdmccormick/url-name branch 4 times, most recently from 7178025 to 28cf4b7 Compare March 10, 2026 15:58
@kdmccormick
Copy link
Member Author

@farhan It's ready now

Copy link
Contributor

@farhan farhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kudos 🚀
Much needed PR to simplify the references and duplicated data

XModuleMixin and CourseOverview both provided some backcompat names
for some XBlock key attributes. Due to refactors that have happened
in edx-platform and improvements to the XBlock API that have happened
over the years, we can now simplify these backcompat mappings. The
new mappings (old -> new) are:

* .course_id -> .context_key
* .location -> .usage_key
* .url_name -> .usage_key.block_id
* .category -> .usage_key.block_type

These are the ways we would like developers to access these
attributes going forward, so it's important that we set the
example in XModuleMixin and CourseOverview.

Note: It is technically correct to go through `.scope_ids` for
these fields, but it's harder to read. Under the hood, the XBlock
API indeed uses `.scope_ids`:
https://github.com/openedx/XBlock/blob/v5.3.0/xblock/core.py#L422-L446

Part of: openedx/xblocks-contrib#125
Defining through usage_key instead of scope_ids broke some tests
which are partially mocking scope_ids
@kdmccormick kdmccormick force-pushed the kdmccormick/url-name branch from 28cf4b7 to 5a0b5c7 Compare March 24, 2026 16:55
@kdmccormick kdmccormick merged commit 919a479 into master Mar 24, 2026
52 checks passed
@kdmccormick kdmccormick deleted the kdmccormick/url-name branch March 24, 2026 17:41
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Aximprovements Team Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants