Skip to content

Remove ability to add media to component versions after initialization#565

Merged
ormsbee merged 2 commits intoopenedx:mainfrom
ormsbee:immutable-cv-media
Apr 29, 2026
Merged

Remove ability to add media to component versions after initialization#565
ormsbee merged 2 commits intoopenedx:mainfrom
ormsbee:immutable-cv-media

Conversation

@ormsbee
Copy link
Copy Markdown
Contributor

@ormsbee ormsbee commented Apr 28, 2026

This implements #561

Media associations must now be specified at the time when new
ComponentVersions are created:

* create_component_version
* create_component_and_version
* create_next_component_version

ComponentVersions are intended to be immutable, and having
create_component_version_media meant that we were encouraging a
pattern where people would create a component version first, and
then make modifications to it after the fact.

This bumps the version to 0.46.0.

Comment thread src/openedx_content/applets/media/models.py
@ormsbee ormsbee marked this pull request as ready for review April 28, 2026 19:33
@ormsbee ormsbee marked this pull request as draft April 28, 2026 19:42
@ormsbee ormsbee force-pushed the immutable-cv-media branch 2 times, most recently from 9f10a84 to 81bdecf Compare April 28, 2026 20:31
@ormsbee ormsbee marked this pull request as ready for review April 28, 2026 20:32
@ormsbee ormsbee changed the title [WIP] Create ComponentVersion with Media assigned Remove ability to add media to component versions after initialization Apr 28, 2026
@ormsbee
Copy link
Copy Markdown
Contributor Author

ormsbee commented Apr 28, 2026

I'll have the companion platform PR up shortly...

@ormsbee ormsbee force-pushed the immutable-cv-media branch from 81bdecf to 2a21462 Compare April 28, 2026 20:42
Media associations must now be specified at the time when new
ComponentVersions are created:

* create_component_version
* create_component_and_version
* create_next_component_version

ComponentVersions are intended to be immutable, and having
create_component_version_media meant that we were encouraging a
pattern where people would create a component version first, and
then make modifications to it after the fact.

This bumps the version to 0.47.0.
Copy link
Copy Markdown
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

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

Nice! Just some suggestions but nothing blocking. I haven't tested this; let me know if you want me to.

Comment thread src/openedx_content/applets/components/api.py
Comment thread src/openedx_content/applets/components/api.py
Comment thread src/openedx_content/applets/components/api.py
normalized_path = path.strip().replace('\\', '/').lstrip('/')
paths_to_media_ids[normalized_path] = media_id

ComponentVersionMedia.objects.bulk_create(
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.

Nice, using bulk_create here will improve performance for anything with multiple pieces of media. Not sure we have much of that yet though.

Comment thread src/openedx_content/applets/components/api.py Outdated
@ormsbee
Copy link
Copy Markdown
Contributor Author

ormsbee commented Apr 29, 2026

Comments addressed in cdab85d. I'm going to squash+merge this and finish the platform PR. I ended up making the path checking stricter.

@ormsbee ormsbee merged commit 0abc619 into openedx:main Apr 29, 2026
6 checks passed
@ormsbee ormsbee deleted the immutable-cv-media branch April 29, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants