Emit events when a learning package is modified [FC-0117]#543
Emit events when a learning package is modified [FC-0117]#543bradenmacdonald wants to merge 23 commits intomainfrom
Conversation
|
Thanks for the pull request, @bradenmacdonald! 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. 🔘 Update the status of your PRYour 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
b92d224 to
67cb958
Compare
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
19b76fa to
4aa66f5
Compare
|
|
||
| old_version: int | None | ||
| """ | ||
| The old version_num of this entity (not the PublishableEntityVersion ID). |
There was a problem hiding this comment.
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)
| 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 |
There was a problem hiding this comment.
Unfortunately, openedx-events doesn't yet support typing so event.kwargs is just a generic dict.
4aa66f5 to
296b74c
Compare
| class ChangeLogRecordData: | ||
| """A single change that was made to a PublishableEntity""" | ||
|
|
||
| entity_id: PublishableEntity.ID |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
@ormsbee @kdmccormick Any opinions on this question ^ ?
Edit: I think I have something in mind that'll work, so no worries / no rush here.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- Just have
publishingemit 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. - 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.
There was a problem hiding this comment.
@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+
716354e to
88f3791
Compare
5b7e2ab to
eb7b160
Compare
Implements #462 .
This updates openedx-code to emit the following events:
1.
LEARNING_PACKAGE_ENTITIES_CHANGEDopenedx-core/src/openedx_content/applets/publishing/signals.py
Lines 90 to 95 in 7ad1e79
2.
LEARNING_PACKAGE_ENTITIES_PUBLISHEDopenedx-core/src/openedx_content/applets/publishing/signals.py
Lines 125 to 129 in 7ad1e79
3.
LEARNING_PACKAGE_COLLECTION_CHANGEDopenedx-core/src/openedx_content/applets/collections/signals.py
Lines 48 to 49 in 7ad1e79
LEARNING_PACKAGE_CREATED/LEARNING_PACKAGE_DELETEDTODOs
Update
set_collectionsto 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