Repository navigation
Description
Background
In other words: it should be safe to call openedx_content directly, rather than be forced to go through xblock_api and libraries_api, and expect that the openedx_content events will be sufficient for edx-platform to manage any downstream effects.
The specific thing that brought this to our attention was libraries indexing. If you call openedx_content directly, then you are allowed to edit library content within Learning Core, but it will not trigger the necessary reindexing within edx-platform. So, we have been forced to create wrapper APIs in edx-platform within the content_libraries_api.
It would be better if the content_libraries_api was only needed for Libraries-specific things (creating a library, renaming library) and that all content operations could safely be done via the openedx_content, triggering events which the content_libraries app would catch and use as a signal to begin reindexing the affected content.
AC
- Define openedx-events for component and container authoring
- Delete
- Publish
- Create/Edit (batched by DraftChangeLog)
- Collection operations
- Fire those events from the openedx_content function calls
- Consume the events in the content_libraries app and reindex content as appropriate
- Consume and react to any other events as appropriate
- Take into account existing events that need to be re-fired based on these new Learning Core events. Hypotheticals:
- xblock_created
- xblock_updated
- library_block_updated
- library_block_published ??
- etc...
DEPR the ones that are non-batch.
Where possible, populate event data from LC rather than by invoking the XBlock runtime.
- As appropriate, move functions from libraries_api down into xblock_api and openedx_content, and/or remove unnecessary libraries_api wrapper functions. Update existing references.
Notes/questions
-
For content edit events, each one should be fired upon commit of the entire DraftChangeLog, not each DraftChangeLogEntry. This way, we get one event per batched edit of entities, rather than one event per entity.
-
Other than reindexing, are there any other instances of handling these events that we think we'll need for Libraries?
-
When we have Courses in Learning Core, the Publish event will be used for many many things. Currently, we catch COURSE_PUBLISHED and have a huge handler that does a lot of things (proctored exam registration, due dates, block transformers, outline generation). As we move to LC, we'll want to move to doing more-scoped recomputation based on these events.
- Need example of "more scoped event handling"
Activity
kdmccormick commentedon Jun 24, 2025
FYI @bradenmacdonald -- as we discussed in Slack
bradenmacdonald commentedon Jun 25, 2025
Thanks for writing this up @kdmccormick !
[-]Fire events from authoring_api to trigger library reindexing[/-][+]Fire events from authoring_api so that downstream effects can be handled in edx-platform[/+][-]Fire events from authoring_api so that downstream effects can be handled in edx-platform[/-][+]Fire events from `openedx_content` so that downstream effects can be handled in edx-platform[/+][-]Fire events from `openedx_content` so that downstream effects can be handled in edx-platform[/-][+]Fire events from `openedx_content` so that downstream effects can be handled in platform[/+]bradenmacdonald commentedon Apr 2, 2026
Doing some analysis of the existing events and how they work:
Authoring Events Specific to Libraries
CONTENT_LIBRARY_CREATEDCONTENT_LIBRARY_DELETEDCONTENT_LIBRARY_UPDATEDLIBRARY_BLOCK_CREATEDLIBRARY_BLOCK_DELETEDLIBRARY_BLOCK_PUBLISHEDLIBRARY_BLOCK_UPDATEDLIBRARY_COLLECTION_CREATEDLIBRARY_COLLECTION_DELETEDLIBRARY_COLLECTION_UPDATEDLIBRARY_CONTAINER_CREATEDLIBRARY_CONTAINER_DELETEDLIBRARY_CONTAINER_PUBLISHEDLIBRARY_CONTAINER_UPDATEDLibraries do not have a "duplicate component" action, so there is no "duplicate" event. Copying and pasting a block results in both
LIBRARY_BLOCK_CREATEDandLIBRARY_BLOCK_UPDATED, which may come out of order (UPDATEDthenCREATED).Authoring Events Specific to Courses
COURSE_CREATEDCOURSE_IMPORT_COMPLETEDCOURSE_RERUN_COMPLETEDCOURSE_CATALOG_INFO_CHANGEDXBLOCK_CREATED-XBLOCK_DELETED-XBLOCK_UPDATED-XBLOCK_PUBLISHED-XBLOCK_DUPLICATEDNote: creating a new course results in:
COURSE_CREATED,COURSE_CATALOG_INFO_CHANGEDx4,XBLOCK_UPDATED(coursexblock) x2,XBLOCK_CREATED(course_infoxblock). Weirdly, I don't see anXBLOCK_CREATEDfor the course root block.Note: creating a new Section results in:
XBLOCK_CREATED(chapterblock) andCOURSE_CATALOG_INFO_CHANGED(?). Similar events are emitted for creating a subsection. But creating a unit only emitsXBLOCK_CREATED, and is not considered a catalog change.Authoring Events (General)
CONTENT_OBJECT_ASSOCIATIONS_CHANGEDwhen tags or collections change. Should fire for any content, regardless of course or library.General Comments
Most of the existing events attach very little data to the event. So little in fact, that I question how useful they are.
For example,
XBLOCK_UPDATEDhas onlyusage_key,block_type(which could be trivially derived from usage_key), andversion. (Theversionfield is problematic for several reasons: it's optional, it's actually an opaque key so should be calledversioned_usage_key, it puts the version info in the key which we want to move away from, it only states the new version not the old version, and it doesn't actually work - in my testing, it was always equal tousage_key).When a library XBlock has changed, the
LIBRARY_BLOCK_UPDATEDevent essentially has only theusage_keyof the updated block, but no other information (it has thelibrary_keybut you can derived that fromusage_keyanyways).Same with the
LIBRARY_BLOCK_PUBLISHEDevent - it has only the usage key, and no information about what changed.The weird exception is the
COURSE_CATALOG_INFO_CHANGEDevent, which provides a relatively large and detailed event payload:{ 'signal': <authoring.course.catalog_info.changed.v1>, 'sender': None, 'catalog_info': CourseCatalogData( course_key=CourseLocator('OpenCraftX', 'NC', '26', None, None), name='A New Course', schedule_data=CourseScheduleData( start=datetime.datetime(2030, 1, 1, 0, 0, tzinfo=...), pacing='instructor', end=None, enrollment_start=None, enrollment_end=None ), hidden=False, invitation_only=False ), 'metadata': EventsMetadata(...), 'from_event_bus': False }bradenmacdonald commentedon Apr 2, 2026
@kdmccormick @ormsbee
I think I have two big open questions about event handling in openedx-core at the moment:
1. Mapping from Learning Package -> high level concepts.
We can emit low-level events like
COMPONENT_UPDATED, with details likelearning_package_id,component_id,component_type_namespace(e.g. xblock),component_type(e.g.video),old_version,new_version. But for practical purposes, consumers of these events will want anXBLOCK_UPDATED_v2event that includes the Learning Context ID and the usage key.The problem is that Open edX Core has no way to map from Learning Package to Learning Context at the moment. For Content Libraries, it's not so hard as the relationship is either 1:0 or 1:1, and it's a simple lookup in the
ContentLibrariestable, but that data is currently only at the platform level, not inopenedx_content. So one option is to make openedx-platform listen for low-levelCOMPONENT_CHANGEDevents and then re-emit them as high levelLIBRARY_BLOCK_UPDATEDorXBLOCK_UPDATED_V2events. Another option is to move the core library model(s) into openedx-core.For Components that are in courses (theoretical), I'm not sure how we're supposed to handle this. If we have several course runs sharing a learning package, I'm not sure what mechanism we plan to have for determining which course run a given component belongs to.
2. Batching
The AC for this issue seems to be encouraging us to move toward batched events where 1 event contains many IDs of changed objects. We can do this because of our nice
DraftChangeLog,PublishLog, etc.But:
So: I don't think that moving to "only batched" events is the way to go, but if we do want to have batched events, and I think we probably should, it might make sense to have a low-level batched event that also emits N smaller, detailed events. e.g. an
ENTITIES_PUBLISHEDbatch event for a group of a dozen changes that leads to a dozen singularXBLOCK_PUBLISHEDevents (which are emitted async if there's > 1, or sync if there's <= 1). As long as there's some way for some actions on single objects to be synchronous and bulk actions to be asynchronous.kdmccormick commentedon Apr 3, 2026
Thanks a bunch for the discovery work @bradenmacdonald .
This is tricky. In the ~Willow timeframe, I think it would make a lot sense to:
but I'm not sure which of those, if any, we could do well by Verawood, especially without having designed Courses for openedx-core yet.
A critical question in designing this will be "Does openedx-core know about XBlocks?". I assume we want that to be "no", but this means refactoring APIs and deciding what the boundary between "Usages"/"Components" (openedx-core) and "XBlocks" (openedx-platform) is, and what the relationship between Usages and Components is.
Yeah, great point. @ormsbee and I talked today and arrived at a similar conclusion. This might actually be enough to get us to Verawood-- imagine a handful of simple batched events:
LEARNING_PACKAGE_ENTITIES_CHANGED,LEARNING_PACKAGE_ENTITIES_PUBLISHED,LEARNING_PACKAGE_COLLECTIONS_CHANGED. openedx-platform could listen to those events instead of the single-block events, and, with the help of the changelogs, both update the Meili index and emit the existing single-block events for backwards compatibilty.What do you think @bradenmacdonald ?
bradenmacdonald commentedon Apr 6, 2026
@kdmccormick Yes, I think something like that makes a lot of sense for Verawood. My only hesitation is that if we end up going in a different direction for Willow, we'll have a lot of different noisy events that we need to keep emitting for backwards compatibility.
kdmccormick commentedon Apr 6, 2026
are you thinking those batched
LEARNING_PACKAGES_*events, or those existing*BLOCK*events?I actually feel pretty solid about the former events as a long-term contract, but let's talk in sync tomorrow to confirm.
I feel less solid about the latter events. But, I don't think we'd be committing to supporting them any more than we are now, we'd just be maintaining the existing behavior.
bradenmacdonald commentedon Apr 6, 2026
These we may want to change depending on how one maps from learning package to context. But if these are always just low level events being re-emitted, then I guess they'd be pretty stable indeed.
Yeah, I think those ones aren't so useful (very little info in them), are under-specified (in what contexts do they get emitted), and aren't future compatible (with non-xblock components like xPLA) but they're also pretty easy to continue supporting so maybe not a big deal.
kdmccormick commentedon Apr 7, 2026
Notes
ENTITIES_CHANGED events
bradenmacdonald commentedon Apr 16, 2026
I have implemented a fully-working
LEARNING_PACKAGE_ENTITIES_CHANGEDevent in #543 . Please take a look if you have a moment.bradenmacdonald commentedon Apr 17, 2026
Should deleting a learning package send out two batch events indicating that all the entities in that learning package have been deleted, and that deletion has been "published"? Or would that be problematic if the event handlers try to load any data when handling the event? Or do we not care, since deleting a learning package is not part of the official API.
bradenmacdonald commentedon Apr 29, 2026
This is done! Though I left tagging events unimplemented for now and proposed a plan for them in #557 .