Skip to content

feat: update content libraries API to use events from openedx-core [FC-0117]#38397

Closed
bradenmacdonald wants to merge 15 commits intoopenedx:kdmccormick/keysfrom
open-craft:braden/events-in-core
Closed

feat: update content libraries API to use events from openedx-core [FC-0117]#38397
bradenmacdonald wants to merge 15 commits intoopenedx:kdmccormick/keysfrom
open-craft:braden/events-in-core

Conversation

@bradenmacdonald
Copy link
Copy Markdown
Contributor

@bradenmacdonald bradenmacdonald commented Apr 21, 2026

Please see the new PR instead: #38437

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Apr 21, 2026
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented Apr 21, 2026

Thanks for the pull request, @bradenmacdonald!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Apr 21, 2026
@bradenmacdonald bradenmacdonald force-pushed the braden/events-in-core branch 2 times, most recently from 999c392 to bdfd169 Compare April 21, 2026 05:56
@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Apr 22, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Apr 22, 2026
@bradenmacdonald bradenmacdonald force-pushed the braden/events-in-core branch 2 times, most recently from 845375f to 7073e07 Compare April 23, 2026 02:36
Comment on lines +454 to +467
{ # Not 100% sure we want this, but a PUBLISHED event is emitted for container 2
# because one of its children's published versions has changed, so whether or
# not it contains unpublished changes may have changed and the search index
# may need to be updated. It is not actually published though.
# TODO: should this be a CONTAINER_CHILD_PUBLISHED event?
# No PUBLISHED event is emitted for container 2, because it doesn't have a published version yet.
# Publishing 'html_block' would have potentially affected it if container 2's published version had a
# reference to 'html_block', but it doesn't yet until we publish it.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's hard to tell from the diff here (because of how it's split up), but before this PR, a spurious PUBLISHED event was emitted for container 2, even though it had never been published. I think the new behavior is much more correct, because it's built on Learning Core's new publish log side effects. I have explained why in the test case and added additional tests to ensure side effects are still resulting in PUBLISHED events when they should be.

@bradenmacdonald bradenmacdonald marked this pull request as ready for review April 23, 2026 17:17
@bradenmacdonald bradenmacdonald changed the base branch from master to kdmccormick/keys April 23, 2026 17:17
Comment on lines +546 to +654
{
"signal": CONTENT_OBJECT_ASSOCIATIONS_CHANGED,
"content_object": ContentObjectChangedData(
object_id=str(container_key),
changes=["collections", "tags"],
),
},
# We used to emit CONTENT_OBJECT_ASSOCIATIONS_CHANGED here for the restored container, specifically noting
# that changes=["collections", "tags"], because deleted things may have collections+tags that are once
# again relevant when it is restored. However, the CREATED event should be sufficient for notifying of that.
# (Or should we emit CREATED+UPDATED to be extra sure?)
Copy link
Copy Markdown
Contributor Author

@bradenmacdonald bradenmacdonald Apr 23, 2026

Choose a reason for hiding this comment

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

Flagging this, as it's a change - no longer emitting CONTENT_OBJECT_ASSOCIATIONS_CHANGED in the case of restoring a deleted object.

TODO: test publishing a thing with collections and tags, delete it, then "revert all changes" in the library UI and make sure it re-appears with collections and tags intact. I haven't tested this yet.

Comment on lines +825 to +841
# openedx_content also lists ancestor containers of the affected units as changed.
# We don't strictly need this at the moment, at least as far as keeping our search index updated.
{
"signal": LIBRARY_CONTAINER_UPDATED,
"library_container": LibraryContainerData(container_key=self.subsection1.container_key),
},
{
"signal": LIBRARY_CONTAINER_UPDATED,
"library_container": LibraryContainerData(container_key=self.subsection2.container_key),
},
{
"signal": LIBRARY_CONTAINER_UPDATED,
"library_container": LibraryContainerData(container_key=self.section1.container_key),
},
{
"signal": LIBRARY_CONTAINER_UPDATED,
"library_container": LibraryContainerData(container_key=self.section2.container_key),
Copy link
Copy Markdown
Contributor Author

@bradenmacdonald bradenmacdonald Apr 23, 2026

Choose a reason for hiding this comment

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

Last change: we now emit events for ancestors of parent containers of modified entities, which we weren't doing before (before it was only one level - parent containers but not their ancestors in turn). I don't think we have a use case for this, but I am not sure if I could or should filter them out somehow, as the publish log treats direct ancestors (which we definitely care about and need events for) and their ancestors in turn exactly the same.

To avoid performance issues, in such cases where more than one ancestor is included in the event stream, the event for the directly modified entity is emitted synchronously but the indirect container events are emitted asynchronously. This seems to work well in the UI, making it update correctly/immediately when e.g. renaming something, but should still preserve performance even if you rename a component used in thousands of different containers.

@kdmccormick kdmccormick force-pushed the kdmccormick/keys branch 3 times, most recently from e41a0a2 to cf8ba1f Compare April 23, 2026 20:02
kdmccormick and others added 8 commits April 23, 2026 16:38
Renames the openedx_django_lib.fields import in EntityLinkBase from
the removed key_field helper to ref_field.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…0.43.0

Updates callers of get_learning_package_by_key (renamed to
get_learning_package_by_ref), create_learning_package, and
update_learning_package to use the new package_ref kwarg, and
switches .key attribute reads to .package_ref.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… 0.43.0

Switches callers of get_publishable_entity_by_key (now _by_ref) to the
new name, and renames .key attribute reads on PublishableEntity,
Component, and Container (via PublishableEntityMixin) to .entity_ref.
Query filters using key__in/entity__key become entity_ref__in/
entity__entity_ref. The set_library_item_collections param entity_key
is renamed to entity_ref for consistency.

Collection.key reads are intentionally left for the collection_code
rename in a later commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…re 0.43.0

Updates callers of get_component_by_key/component_exists_by_key (now
_by_code) and switches the local_key kwarg on create_component,
create_component_and_version, and related queries to component_code.
Also renames component.local_key reads to component.component_code and
adjusts a modulestore_migrator container query that filtered on
publishable_entity__key (now entity_ref).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…edx-core 0.43.0

Switches get_container_by_key to get_container_by_code and renames the
container creation kwarg from key to container_code for both
create_container_and_version and its platform wrapper. Updates
ComponentVersionMedia accesses: the model field .key becomes .path,
and create_component_version_media's key kwarg becomes path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…-core 0.43.0

Renames all Collection APIs that took key/collection_key to use
collection_code: create_collection, update_collection, delete_collection,
restore_collection, add_to_collection, etc. Switches Collection.key
attribute reads to .collection_code across tests, signal handlers,
search indexers, and modulestore_migrator. Filters like
target_collection__key become target_collection__collection_code.

Also updates the library restore serializer to track the renamed
lp_restored_data fields: archive_org_key -> archive_org_code,
archive_slug -> archive_package_code, key -> package_ref,
archive_lp_key -> archive_package_ref. The archive_org_code and
archive_package_code fields now allow None, since openedx-core no
longer raises ValueError when the archive_package_ref cannot be
parsed as {prefix}:{org_code}:{package_code}.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
	fix: build locator with container_code

	fix: pylint and mypy

	fix: queries for search index

	fix: some missed cvm.key -> cvm.path

	fix: undo breaking library changes

	fix: openedx-core no longer raises integrityerror on conflict

	fix: misses in modulestore_migrator

	fix: search tests

	docs: Improve collection_code/key TODO comment
This is necessary because we are no longer presuming that package_ref
follows the same format as a Content Library. In the future, we may
want a more graceful way of handling this.
@kdmccormick kdmccormick deleted the branch openedx:kdmccormick/keys April 23, 2026 21:44
@github-project-automation github-project-automation Bot moved this from Waiting on Author to Done in Contributions Apr 23, 2026
@bradenmacdonald
Copy link
Copy Markdown
Contributor Author

New PR since this one was automatically closed and can't be re-opened: #38437

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants