Skip to content

Emit events when a learning package is modified [FC-0117]#543

Draft
bradenmacdonald wants to merge 23 commits intomainfrom
braden/emit-events
Draft

Emit events when a learning package is modified [FC-0117]#543
bradenmacdonald wants to merge 23 commits intomainfrom
braden/emit-events

Conversation

@bradenmacdonald
Copy link
Copy Markdown
Contributor

@bradenmacdonald bradenmacdonald commented Apr 15, 2026

Implements #462 .

This updates openedx-code to emit the following events:

1. LEARNING_PACKAGE_ENTITIES_CHANGED

The draft version of one or more entities in a `LearningPackage` has changed.
This is emitted when the first version of an entity is **created**, when a new
version of an entity is created (i.e. an entity is **modified**), when an entity
is **reverted** to an old version, when **a dependency is modified**, or when an
entity is **deleted**. (All referring to the draft version of the entity.)

2. LEARNING_PACKAGE_ENTITIES_PUBLISHED

This is emitted when **a newly-created entity is first published**, when
**changes to an existing entity** are published, when **changes to a
dependency** (or a dependency's dependencies...) are published, when a published
entity is **reverted** to a previous version, or when **a "delete" is
published**.

3. LEARNING_PACKAGE_COLLECTION_CHANGED

A ``Collection`` has been created, modified, or deleted, or its entities have
changed.

  1. TODO - LEARNING_PACKAGE_CREATED / LEARNING_PACKAGE_DELETED

TODOs

Update set_collections to emit events asynchronously if needed?

Notes

Tagging events are much more complicated so will be in their own PR. The proposed spec is at #557

Platform PR

openedx/openedx-platform#38397

@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 15, 2026
@openedx-webhooks
Copy link
Copy Markdown

Thanks for the pull request, @bradenmacdonald!

This repository is currently maintained by @axim-engineering.

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.

🔘 Update the status of your PR

Your PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate.


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 15, 2026
@bradenmacdonald bradenmacdonald changed the title Emit events when a learning package is modified Emit events when a learning package is modified [FC-0117] Apr 16, 2026
@bradenmacdonald bradenmacdonald added the FC Relates to an Axim Funded Contribution project label Apr 16, 2026
@bradenmacdonald bradenmacdonald force-pushed the braden/emit-events branch 2 times, most recently from 19b76fa to 4aa66f5 Compare April 16, 2026 00:19

old_version: int | None
"""
The old version_num of this entity (not the PublishableEntityVersion ID).
Copy link
Copy Markdown
Contributor Author

@bradenmacdonald bradenmacdonald Apr 16, 2026

Choose a reason for hiding this comment

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

Working on this PR has made me want to add fully-typed IDs for PublishableEntityVersion and some kind of VersionNum type, because we do mix and match those a bit in the code, but they're very different things.

(I made PublishableEntity.id fully-typed but hadn't yet done ___Version)

Comment on lines +44 to +52
assert event.signal is api.signals.LEARNING_PACKAGE_ENTITIES_CHANGED
assert event.kwargs["learning_package"].id == learning_package.id
assert event.kwargs["learning_package"].title == "Test LP 📦"
assert event.kwargs["changed_by"].user_id is None
assert event.kwargs["change_log"].draft_change_log_id == expected_draft_change_log_id
assert event.kwargs["change_log"].changes == [
api.signals.ChangeLogRecord(entity_id=entity.id, old_version=None, new_version=NEW_VERSION_NUM),
]
assert event.kwargs["metadata"].time == now_time
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.

Unfortunately, openedx-events doesn't yet support typing so event.kwargs is just a generic dict.

class ChangeLogRecordData:
"""A single change that was made to a PublishableEntity"""

entity_id: PublishableEntity.ID
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.

Should I include container_type, component_type, container_code, and component_code in these ChangeLogRecords? I think so, but I currently implemented this entirely within the publishing app, and doing so would require either making publishing aware of containers/components or moving the signals out of publishing to become generic openedx_content signals. Perhaps I could even make signals its own applet?

Copy link
Copy Markdown
Contributor Author

@bradenmacdonald bradenmacdonald Apr 16, 2026

Choose a reason for hiding this comment

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

@ormsbee @kdmccormick Any opinions on this question ^ ?

Edit: I think I have something in mind that'll work, so no worries / no rush here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bradenmacdonald sorry for the slow response. My hunch is to make a signals applet, given that this might not be the only instance where we want to respond with Data objects with cross-applet information. Kinda like how backup_restore works with data from across all the lower applets. Curious what you come up with, though.

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.

I do also like the signals or events applet approach, but the challenge is that there aren't good hooks into publishing/collections to use, so to support that still requires publishing/collections/tagging to emit internal signals, then the new events applet to receive them + enrich them and re-emit them as public signals, but then we're still missing the context info like library key, so platform has to receive and re-emit them yet again. I'm playing around with this on the platform side, but I'm thinking for now it's simpler to just have one set of low-level events emitted from Learning Core and have them re-emitted in the platform, which we can later change to be re-emitted from Learning Core itself.

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.

This is actually a perfect example of why having a single consolidated EntityType in the publishing app would be excellent, as opposed to ComponentType/ContainerType that publishing isn't aware of.

Before @kdmccormick's changes, the PublishableEntity.key could also have been included in events and used to basically provide the container/component type (e.g. xblock.v1:problem:my-key vs. unit:my-unit) albeit in a way that requires parsing and is not ideal - but is efficient in terms of avoiding JOINs/queries.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An additional thing I'll note is that not all LearningPackages will have a library key. Leaving aside a future with courses, we currently create a detached LearningPackage when a restore happens, and then hook it up to a library after the fact.

Maybe we could do some kind of dependency injection thing where publishing is about to fire off a draft-change or publish event, and the different apps are given an opportunity to add their own select_related bits to the queryset?

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.

Yeah, I was thinking that too. But (a) even using dependency injection, it creates a bit of a messy circular data flow between publishing and containers/components, and (b) the event types are defined statically, so even if we can inject extra select_related into the queryset, the event data doesn't define additional fields unless we say "there's a random dict of extra data on each event" or move the events to a higher level.

What I'm leaning at the moment:

  1. Just have publishing emit a single batch event for most changes, and platform can listen to that, annotate/enrich it with context+container+component info, and emit high-level non-batch events for each modified entity (in a celery task). An additional query here with various new JOINs is not going to hurt performance much, as it's still a big batch event and it can be done async when N_entities_modified > 1.
  2. Later, we can look at moving "Learning Context" / library / course into openedx_core, and possibly consolidating ComponentType+ContainerType into EntityType. Then openedx_core can emit the same events directly. But that would be a future optimization and not necessary.

Although this isn't "optimal" in terms of reducing the number of events, I do think it has the cleanest separation of concerns given our current architecture. The publishing app just focuses on entities and learning packages which are its main primitives, and higher-level code does higher-level events.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bradenmacdonald yup, I agree that (1) the best approach for now given the constraints we have, and everything in (2) is worth considering for Willow+

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Apr 16, 2026
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: Waiting on Author

Development

Successfully merging this pull request may close these issues.

5 participants