feat!: Collection.key -> Collection.collection_code#542
Conversation
1489024 to
9875433
Compare
7eb00fd to
b3daece
Compare
Also, standardize internal usage of collection_key to collection_code. This helps clarify that Collection.key is *not* an OpaqueKey, but is rather a local slug, which can be combined with other identifiers to form a fully- qualified LibraryCollectionKey instance. BREAKING CHANGE: Collection.key has been renamed to Collection.collection_code. BREAKING CHANGE: Collection.collection_code now validates that its contents matches '[A-Za-z0-9\-\_\.]+'. This was already effectively true, because LibraryCollectionKey can only be built with slug-like parts, but we now we explicitly raise ValiationError from create_collection. Backup now writes both 'key' and 'collection_code' to collection TOML files, so older software (which only knows 'key') can still read new archives. Restore accepts either field, preferring 'collection_code' and falling back to the legacy 'key'. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Part of: #322
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…llection_code' The backup_restore archive format stays unchanged — collections are still serialized with "key". A comment notes the divergence from the model field name (collection_code) and that a future v2 format may align them. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds a code_field_check(field_name, name=...) companion to code_field() that returns a CheckConstraint using Django's Regex lookup. This enforces the code regex at the database level (not just via validators), and Django also runs it as a Python-level validator automatically. Applied to Collection.collection_code as the first usage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
b3daece to
d55764c
Compare
…zer.validate() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| def update_collection( | ||
| learning_package_id: LearningPackage.ID, | ||
| key: str, | ||
| collection_code: str, |
There was a problem hiding this comment.
Not at all a blocker, but something to consider for the future: our APIs are a bit inconsistent about how we identify the "thing" we're modifying in each API call.
My preference is this style where you can pass in an instance or a primary key:
openedx-core/src/openedx_catalog/api_impl.py
Lines 63 to 64 in 10eae2d
openedx-core/src/openedx_content/applets/containers/api.py
Lines 454 to 455 in 10eae2d
But this collection API is now using a composite (lp_id, collection_code) pattern:
openedx-core/src/openedx_content/applets/collections/api.py
Lines 67 to 69 in 0614fcb
And other APIs accept only an ID:
openedx-core/src/openedx_content/applets/components/api.py
Lines 155 to 156 in 10eae2d
And other APIs accept only an instance:
openedx-core/src/openedx_tagging/api.py
Lines 436 to 437 in 10eae2d
There was a problem hiding this comment.
I agree, this would be great to fix soon
bradenmacdonald
left a comment
There was a problem hiding this comment.
I didn't test this but the code changes look great. Thanks!
|
|
||
| dependencies = [ | ||
| ('openedx_content', '0007_publishlogrecord_direct'), | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), |
There was a problem hiding this comment.
This might be another Claude artifact. This migration does not actually depend on the AUTH_USER_MODEL.
There was a problem hiding this comment.
I presume we only need it for migrations which touch an FK to User?
There was a problem hiding this comment.
Yes, I looked and every migration in core that has this dependency has a reference to settings. AUTH_USER_MODEL elsewhere in the list of changes.
Description
Also, standardize internal usage of collection_key to collection_code.
This helps clarify that Collection.key is not an OpaqueKey, but is rather
a local slug, which can be combined with other identifiers to form a fully-
qualified LibraryCollectionKey instance.
BREAKING CHANGE: Collection.key has been renamed to Collection.collection_code.
BREAKING CHANGE: Collection.collection_code now validates that its contents
matches '[A-Za-z0-9-_.]+'. This was already effectively true, because
LibraryCollectionKey can only be built with slug-like parts, but we now
we explicitly raise ValiationError from create_collection.
Backup-restore still write and reads the collection_code to/from TOML files as
keyfor backwards compatibility. This may change in a future "v2" restore format.Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com
Part of:
Full series of PRs:
keysare now opaquerefs#546Testing, AI Usage, and Merge Considerations
See #322