Skip to content

feat!: Component.local_key -> Component.component_code#544

Merged
kdmccormick merged 4 commits intomainfrom
kdmccormick/keys-component
Apr 20, 2026
Merged

feat!: Component.local_key -> Component.component_code#544
kdmccormick merged 4 commits intomainfrom
kdmccormick/keys-component

Conversation

@kdmccormick
Copy link
Copy Markdown
Member

@kdmccormick kdmccormick commented Apr 15, 2026

Description

BREAKING CHANGE: Component.local_key has been renamed to
Component.component_code.

BREAKING CHANGE: Component.component_code now validates against
[A-Za-z0-9-_.]+ and has a max_length of 255. Previously local_key used
key_field() (no regex validation, max_length=500).

BREAKING CHANGE: Function parameters renamed from local_key to component_code
in create_component(...) and create_component_and_version(...).

BREAKING CHANGE: Functions
get_component_by_key(...)/component_exists_by_key(...), renamed to
get_component_by_code(...)/component_exists_by_code(...), and parameters
renamed from local_key to component_code.

Backup-restore format is unchanged. component_type and component_code
will continue to be parsed from the entity key. This may change in
a future "v2" backup format.

Part of: #322

Full series of PRs:

  1. feat!: Collection.key -> Collection.collection_code #542
  2. feat!: Component.local_key -> Component.component_code #544
  3. feat!: Add Container.container_code field #545
  4. feat!: Package and Entity keys are now opaque refs #546
  5. feat!: ComponentVersionMedia.key -> ComponentVersionMedia.path #547

Testing, AI Usage, and Merge Considerations

See #322

@kdmccormick kdmccormick force-pushed the kdmccormick/keys-collection branch from 1489024 to 9875433 Compare April 15, 2026 09:42
@kdmccormick kdmccormick force-pushed the kdmccormick/keys-component branch from 944a2c3 to fbe4b4b Compare April 15, 2026 10:06
@kdmccormick kdmccormick force-pushed the kdmccormick/keys-collection branch from b3daece to d55764c Compare April 16, 2026 17:04
@kdmccormick kdmccormick force-pushed the kdmccormick/keys-component branch 3 times, most recently from 0f875ed to 2bf60ff Compare April 17, 2026 16:35
@kdmccormick kdmccormick marked this pull request as ready for review April 17, 2026 17:59
@ormsbee ormsbee self-requested a review April 17, 2026 18:39
Base automatically changed from kdmccormick/keys-collection to main April 17, 2026 18:43
@kdmccormick kdmccormick force-pushed the kdmccormick/keys-component branch from 2bf60ff to 382a7b3 Compare April 17, 2026 18:45
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.

Thanks, looks great! I did not test this, just read the code.

Comment thread src/openedx_content/applets/components/models.py
@ormsbee ormsbee removed their request for review April 17, 2026 19:21
Copy link
Copy Markdown
Contributor

@ormsbee ormsbee left a comment

Choose a reason for hiding this comment

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

Just a question about backwards compatibility. I'm not sure it's a blocker, but I would like to understand it better.

Comment on lines +111 to +118
if hasattr(entity, "component"):
component = entity.component
component_table = tomlkit.table()
# Write component_type and component_code explicitly so that restore
# (Verawood and later) does not need to parse the entity key.
component_table.add("component_type", str(component.component_type))
component_table.add("component_code", component.component_code)
entity_table.add("component", component_table)
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.

Question: What happens when an Ulmo instance reads this?

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.

I mean, I get that it won't understand the new component_code piece. But does it successfully import components that have an explicit [component] section, since that wasn't being written to the TOML previously?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm, I'm currently hitting an issue where any archive which I unzip or re-zip fails to restore, regardless of whether I edit the contents or not, with the message Errors encountered during restore: package.toml: Missing learning package file. Archive that are never unzipped restore fine. I'm seeing this on the Ulmo sandbox, and I'm zipping using macOS's built in "Compress" utility. I'll try it later locally and see if I can get logs, and will try re-zipping with other methods....

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Haven't figured out this ⬆️ issue yet, but I did verify through unit tests that [component] and [container] seem safe to add without breaking Ulmo: #552

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm, I'm currently hitting an issue where any archive which I unzip or re-zip fails to restore, regardless of whether I edit the contents or not, with the message Errors encountered during restore: package.toml: Missing learning package file.

ah, duh, I was making a ZIP where collection, entities and package.toml were nested within a top-level rather than being top-level items themselves.

with that figured out, I verified manually that [component] and [container] are safe to add 👍🏻

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ohp, just realized I should be testing [entity.component] and [entity.container]. Testing now

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See discussion on #552

Renames the Component.local_key field to component_code, switching
from key_field() to code_field() (stricter validation: [A-Za-z0-9\-\_\.]+,
max_length=255). Updates all API call sites, backup/restore, and tests.

Backup/restore now writes an [entity.component] section in each component
TOML file containing component_type and component_code explicitly, so that
restore does not need to parse the entity key. Old archives (without the
[entity.component] section) are still accepted by falling back to the
existing entity key parsing.

BREAKING CHANGE: Component.local_key has been renamed to Component.component_code.

BREAKING CHANGE: Component.component_code now validates against
[A-Za-z0-9\-\_\.]+  and has a max_length of 255. Previously local_key
used key_field() (no regex validation, max_length=500).

BREAKING CHANGE: Function parameters renamed from local_key to component_code
in create_component(...) and create_component_and_version(...).

BREAKING CHANGE: Functions get_component_by_key(...)/component_exists_by_key(...),
renamed to get_component_by_code(...)/component_exists_by_code(...), and
parameters renamed from local_key to component_code.

Part of: #322

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kdmccormick kdmccormick force-pushed the kdmccormick/keys-component branch from 70009c5 to d7dc148 Compare April 20, 2026 16:45
Comment thread src/openedx_content/applets/backup_restore/serializers.py Outdated
@kdmccormick kdmccormick force-pushed the kdmccormick/keys-component branch from d7dc148 to 13cad83 Compare April 20, 2026 16:52
@kdmccormick kdmccormick requested a review from ormsbee April 20, 2026 16:54
@kdmccormick kdmccormick enabled auto-merge (squash) April 20, 2026 18:11
@kdmccormick kdmccormick merged commit cbc344b into main Apr 20, 2026
6 checks passed
@kdmccormick kdmccormick deleted the kdmccormick/keys-component branch April 20, 2026 18:14
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