Bug: deleting a v2 library that ever held a container returns 500

Author: bmtcrilCreated Sep 17, 2026Updated Sep 17, 2026
Labelsbughelp wanted

Where: DELETE /api/libraries/v2/<lib>/ (content_libraries/rest_api/libraries.py deleteapi/libraries.py delete_library) on Tutor main (edx-platform master e2e8edf73f).

What happens: a library that only ever held components deletes cleanly (200 {}, then 404). A library that has had a unit/subsection/section, or a publish with side effects, answers 500 {"error": "The Studio servers encountered an error"}; the CMS log shows django.db.models.deletion.RestrictedError: Cannot delete some instances of model 'LearningPackage' because they are referenced through restricted foreign keys: 'EntityListRow.entity', 'DraftSideEffect.cause', 'DraftSideEffect.effect', 'PublishSideEffect.cause', 'PublishSideEffect.effect'.

Expected: Probably a descriptive 400 error

Source: openedx/openedx-platform