Skip to content

Commit 42ce7af

Browse files
kdmccormickclaude
andcommitted
fix(squash): rename get_container_by_ref to get_container_by_code
Looks up by container_code directly on the Container model instead of going through publishable_entity__entity_ref. BREAKING CHANGE: get_container_by_ref() has been renamed to get_container_by_code() and its parameter changed from entity_ref to container_code. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5f15777 commit 42ce7af

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

  • src/openedx_content/applets/containers
  • tests/openedx_content/applets/containers

src/openedx_content/applets/containers/api.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"create_next_container_version",
5656
"get_container",
5757
"get_container_version",
58-
"get_container_by_ref",
58+
"get_container_by_code",
5959
"get_all_container_subclasses",
6060
"get_container_subclass",
6161
"get_container_type_code_of",
@@ -569,22 +569,22 @@ def get_container_version(container_version_pk: int) -> ContainerVersion:
569569
return ContainerVersion.objects.get(pk=container_version_pk)
570570

571571

572-
def get_container_by_ref(learning_package_id: LearningPackage.ID, /, entity_ref: str) -> Container:
572+
def get_container_by_code(learning_package_id: LearningPackage.ID, /, container_code: str) -> Container:
573573
"""
574574
[ 🛑 UNSTABLE ]
575-
Get a container by its learning package and entity ref.
575+
Get a container by its learning package and container code.
576576
577577
Args:
578578
learning_package_id: The ID of the learning package that contains the container.
579-
entity_ref: The entity ref of the container.
579+
container_code: The container code of the container.
580580
581581
Returns:
582-
The container with the given entity ref (as `Container`, not as its typed subclass).
582+
The container with the given container code (as `Container`, not as its typed subclass).
583583
"""
584584
try:
585585
return Container.objects.select_related("container_type").get(
586-
publishable_entity__learning_package_id=learning_package_id,
587-
publishable_entity__entity_ref=entity_ref,
586+
learning_package_id=learning_package_id,
587+
container_code=container_code,
588588
)
589589
except Container.DoesNotExist:
590590
# Check if it's the container or the learning package that does not exist:

tests/openedx_content/applets/containers/test_api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -761,29 +761,29 @@ def test_get_container_version_nonexistent() -> None:
761761
containers_api.get_container_version(-500)
762762

763763

764-
# get_container_by_ref
764+
# get_container_by_code
765765

766766

767-
def test_get_container_by_ref(lp: LearningPackage, parent_of_two: TestContainer) -> None:
767+
def test_get_container_by_code(lp: LearningPackage, parent_of_two: TestContainer) -> None:
768768
"""
769-
Test getting a specific container by entity ref
769+
Test getting a specific container by container code.
770770
"""
771-
result = containers_api.get_container_by_ref(lp.id, parent_of_two.entity_ref)
771+
result = containers_api.get_container_by_code(lp.id, parent_of_two.container_code)
772772
assert result == parent_of_two.container
773773
# The API always returns "Container", not specific subclasses like TestContainer:
774774
assert result.__class__ is Container
775775

776776

777-
def test_get_container_by_ref_nonexistent(lp: LearningPackage) -> None:
777+
def test_get_container_by_code_nonexistent(lp: LearningPackage) -> None:
778778
"""
779-
Test getting a specific container by entity ref, where the ref and/or learning package is invalid
779+
Test getting a specific container by container code, where the code and/or learning package is invalid.
780780
"""
781781
FAKE_ID = cast(LearningPackage.ID, -500)
782782
with pytest.raises(LearningPackage.DoesNotExist):
783-
containers_api.get_container_by_ref(FAKE_ID, "invalid-ref")
783+
containers_api.get_container_by_code(FAKE_ID, "invalid-code")
784784

785785
with pytest.raises(Container.DoesNotExist):
786-
containers_api.get_container_by_ref(lp.id, "invalid-ref")
786+
containers_api.get_container_by_code(lp.id, "invalid-code")
787787

788788

789789
# get_container_subclass

0 commit comments

Comments
 (0)