-
Notifications
You must be signed in to change notification settings - Fork 4.2k
refactor!: use String field instead of Dict field to store top_level_downstream_parent_key #37448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
51f58a4
3c24211
d5b0100
76f75e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,7 @@ | |
| Consider moving these into opaque-keys if they generalize well. | ||
| """ | ||
| import hashlib | ||
| from typing import NamedTuple | ||
|
|
||
| from typing import NamedTuple, Self | ||
|
|
||
| from opaque_keys.edx.keys import UsageKey | ||
|
|
||
|
|
@@ -28,6 +27,19 @@ class BlockKey(NamedTuple): | |
| def from_usage_key(cls, usage_key): | ||
| return cls(usage_key.block_type, usage_key.block_id) | ||
|
|
||
| def __str__(self) -> str: | ||
| return f"{self.type}:{self.id}" | ||
|
|
||
| @classmethod | ||
| def from_string(cls, s: str) -> Self: | ||
| """ | ||
| Convert a BlockKey string into a BlockKey object. | ||
| """ | ||
| parts = s.split(':') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for parsing robustness, can we throw a ValueError here if there are not exactly two string parts, both non-empty?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is why I should not let AI autocomplete more than a line 😝 Updated here: 8fee843 |
||
| if len(parts) != 2 or not parts[0] or not parts[1]: | ||
| raise ValueError(f"Invalid string format for BlockKey: {s}") | ||
| return cls(parts[0], parts[1]) | ||
|
|
||
|
|
||
| def derive_key(source: UsageKey, dest_parent: BlockKey) -> BlockKey: | ||
| """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.