feat!: Add Container.container_code field#545
Conversation
62746d6 to
845c3c7
Compare
944a2c3 to
fbe4b4b
Compare
845c3c7 to
fbe4b4b
Compare
0f70804 to
266d7f3
Compare
fbe4b4b to
f4d32b8
Compare
266d7f3 to
5283857
Compare
f4d32b8 to
0f875ed
Compare
5283857 to
c32f78c
Compare
0f875ed to
2bf60ff
Compare
8434cbf to
64f0eeb
Compare
2bf60ff to
382a7b3
Compare
64f0eeb to
f67afa4
Compare
bradenmacdonald
left a comment
There was a problem hiding this comment.
I'm fine with this, assuming it's immediately followed by the proper removal of the key field, but I'd prefer to replace key more 1 for 1 as mentioned. Did not run the code, just read.
ormsbee
left a comment
There was a problem hiding this comment.
Just a sanity check question, but otherwise LGTM.
| Container = apps.get_model("openedx_content", "Container") | ||
| for container in Container.objects.select_related("publishable_entity__learning_package").all(): | ||
| container.learning_package = container.publishable_entity.learning_package | ||
| container.container_code = container.publishable_entity.key | ||
| container.save(update_fields=["learning_package", "container_code"]) |
There was a problem hiding this comment.
[Comment, no action needed] It's really unfortunate that we can't use F() across relations. I feel like this is one of the few cases where I'd be tempted to use raw SQL.
d7dc148 to
13cad83
Compare
Adds a container_code field (code_field) and a learning_package FK to the Container model. Also adds a UniqueConstraint on (learning_package, container_code), which is stricter than Component's constraint (no type scoping -- container codes must be unique across all container types within a given LearningPackage). For existing containers, container_code is backfilled from the entity key via a data migration. Future containers will have container_code set explicitly by the caller. Backup/restore now writes container_code into the [entity.container] section (Verawood and later). Archives created in Ulmo (which have no container_code) fall back to using the entity key as the container_code on restore. BREAKING CHANGE: create_container() and create_container_and_version() now require a container_code keyword argument. The same applies to create_unit_and_version(), create_subsection_and_version(), and create_section_and_version(). Part of: #322 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
f67afa4 to
ed3aadc
Compare
bdbebec to
f42b544
Compare
|
Thanks for the review @bradenmacdonald . I've applied all your suggestions except the denormalization check. Could you take another look? |
| # Unlike component_code, it is unique across all container types within | ||
| # the same LearningPackage. |
There was a problem hiding this comment.
Will requiring this code to be unique across all containers in a [course] bite us later when we try to migrate old courses to Learning Core, since they may have e.g. a section and unit with the same container_code ?
There was a problem hiding this comment.
Hard to say.
On one hand, we'll likely have multiple course runs per learning package. So, we'll need to handle collisions between container block url_names anyway. I'm imagining that there'll have to be a table which maps CourseRunUsages to Entities, rather than a simple mapping function between {component,container}_{type,code} and CourseRunUsageKeys.
On the other hand, it's weird to me that container_code and component_code have different uniqueness constraints. I have a feeling that the inconsistency will make consuming code more complicated rather than having any benefit to us.
We're riding the line now, but maybe we can sneak a fix to this in before the cutoff.
There was a problem hiding this comment.
Yeah, I'd prefer to make container_code work like component_code if we can.
bradenmacdonald
left a comment
There was a problem hiding this comment.
Looks great! I read through the code, but didn't test; let me know if you want any testing on these PRs.
|
@bradenmacdonald all set for now, but if you if you have time on Wednesday I could use a hand testing the openedx-platform PR. |
Description
Adds a container_code field (code_field) and a learning_package FK to the
Container model. Also adds a UniqueConstraint on (learning_package,
container_code), which is stricter than Component's constraint (no type scoping
-- container codes must be unique across all container types within a given
LearningPackage).
For existing containers, container_code is backfilled from the entity key via a
data migration. Future containers will have container_code set explicitly by the
caller.
BREAKING CHANGE: In create_container() and create_container_and_version(), the
keyargument has been renamed tocontainer_code. The same applies tocreate_unit_and_version(), create_subsection_and_version(), and
create_section_and_version().
Backup-restore format is unchanged. container_code will be set to the value of
the entity key. This may change in a future "v2" backup format.
Part of: #322
Full series of PRs:
keysare now opaquerefs#546Testing, AI Usage, and Merge Considerations
See #322