Skip to content

Commit 09bbd04

Browse files
kdmccormickclaude
andcommitted
fix(squash): derive entity_ref from code fields, don't accept it as a parameter
Container and component creation functions no longer accept entity_ref. It is always derived: containers use container_code, components use "{namespace}:{type_name}:{component_code}". Only the low-level create_publishable_entity() still accepts entity_ref directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b9d11db commit 09bbd04

6 files changed

Lines changed: 3 additions & 25 deletions

File tree

src/openedx_content/applets/backup_restore/zipper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,6 @@ def _save_container(
836836
container = containers_api.create_container(
837837
learning_package.id,
838838
**data, # should this be allowed to override any of the following fields?
839-
entity_ref=entity_ref,
840839
created_by=self.user_id,
841840
container_cls=container_cls,
842841
)

src/openedx_content/applets/components/api.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,14 @@ def create_component(
8282
created_by: int | None,
8383
*,
8484
can_stand_alone: bool = True,
85-
entity_ref: str | None = None,
8685
) -> Component:
8786
"""
8887
Create a new Component (an entity like a Problem or Video).
8988
90-
If ``entity_ref`` is not provided, it defaults to
89+
The ``entity_ref`` is always derived as
9190
``"{namespace}:{type_name}:{component_code}"``.
9291
"""
93-
if entity_ref is None:
94-
entity_ref = f"{component_type.namespace}:{component_type.name}:{component_code}"
92+
entity_ref = f"{component_type.namespace}:{component_type.name}:{component_code}"
9593
with atomic():
9694
publishable_entity = publishing_api.create_publishable_entity(
9795
learning_package_id,
@@ -282,13 +280,9 @@ def create_component_and_version( # pylint: disable=too-many-positional-argumen
282280
created_by: int | None = None,
283281
*,
284282
can_stand_alone: bool = True,
285-
entity_ref: str | None = None,
286283
) -> tuple[Component, ComponentVersion]:
287284
"""
288285
Create a Component and associated ComponentVersion atomically.
289-
290-
If ``entity_ref`` is not provided, it defaults to
291-
``"{namespace}:{type_name}:{component_code}"``.
292286
"""
293287
with atomic():
294288
component = create_component(
@@ -298,7 +292,6 @@ def create_component_and_version( # pylint: disable=too-many-positional-argumen
298292
created,
299293
created_by,
300294
can_stand_alone=can_stand_alone,
301-
entity_ref=entity_ref,
302295
)
303296
component_version = create_component_version(
304297
component.id,

src/openedx_content/applets/containers/api.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ def create_container(
142142
container_code: str,
143143
container_cls: type[ContainerModel],
144144
can_stand_alone: bool = True,
145-
entity_ref: str | None = None,
146145
) -> ContainerModel:
147146
"""
148147
[ 🛑 UNSTABLE ]
@@ -156,17 +155,13 @@ def create_container(
156155
the learning package (regardless of container type).
157156
container_cls: The subclass of container to create (e.g. `Unit`)
158157
can_stand_alone: Set to False when created as part of containers
159-
entity_ref: Optional opaque reference string. Defaults to container_code.
160-
# TODO: The dev team is considering revisiting the default container
161-
# entity_ref derivation in the future.
162158
163159
Returns:
164160
The newly created container as an instance of `container_cls`.
165161
"""
166162
assert issubclass(container_cls, Container)
167163
assert container_cls is not Container, "Creating plain containers is not allowed; use a subclass of Container"
168-
if entity_ref is None:
169-
entity_ref = container_code # TODO: The team may revisit this default derivation.
164+
entity_ref = container_code
170165
with atomic():
171166
publishable_entity = publishing_api.create_publishable_entity(
172167
learning_package_id,
@@ -356,7 +351,6 @@ def create_container_and_version(
356351
created: datetime,
357352
created_by: int | None = None,
358353
can_stand_alone: bool = True,
359-
entity_ref: str | None = None,
360354
) -> tuple[ContainerModel, ContainerVersionModel]:
361355
"""
362356
[ 🛑 UNSTABLE ] Create a new container and its initial version.
@@ -375,7 +369,6 @@ def create_container_and_version(
375369
created: The creation date.
376370
created_by: The ID of the user who created the container.
377371
can_stand_alone: Set to False when created as part of containers
378-
entity_ref: Optional opaque reference string. Defaults to container_code.
379372
"""
380373
with atomic(savepoint=False):
381374
container = create_container(
@@ -385,7 +378,6 @@ def create_container_and_version(
385378
container_code=container_code,
386379
can_stand_alone=can_stand_alone,
387380
container_cls=container_cls,
388-
entity_ref=entity_ref,
389381
)
390382
container_version: ContainerVersionModel = create_container_version( # type: ignore[assignment]
391383
container.id,

src/openedx_content/applets/sections/api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def create_section_and_version(
3838
created: datetime,
3939
created_by: int | None = None,
4040
can_stand_alone: bool = True,
41-
entity_ref: str | None = None,
4241
) -> tuple[Section, SectionVersion]:
4342
"""
4443
See documentation of `content_api.create_container_and_version()`
@@ -50,7 +49,6 @@ def create_section_and_version(
5049
section, sv = containers_api.create_container_and_version(
5150
learning_package_id,
5251
container_code=container_code,
53-
entity_ref=entity_ref,
5452
title=title,
5553
entities=subsections,
5654
created=created,

src/openedx_content/applets/subsections/api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def create_subsection_and_version(
3838
created: datetime,
3939
created_by: int | None = None,
4040
can_stand_alone: bool = True,
41-
entity_ref: str | None = None,
4241
) -> tuple[Subsection, SubsectionVersion]:
4342
"""
4443
See documentation of `content_api.create_container_and_version()`
@@ -50,7 +49,6 @@ def create_subsection_and_version(
5049
subsection, sv = containers_api.create_container_and_version(
5150
learning_package_id,
5251
container_code=container_code,
53-
entity_ref=entity_ref,
5452
title=title,
5553
entities=units,
5654
created=created,

src/openedx_content/applets/units/api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def create_unit_and_version(
3838
created: datetime,
3939
created_by: int | None = None,
4040
can_stand_alone: bool = True,
41-
entity_ref: str | None = None,
4241
) -> tuple[Unit, UnitVersion]:
4342
"""
4443
See documentation of `content_api.create_container_and_version()`
@@ -50,7 +49,6 @@ def create_unit_and_version(
5049
unit, uv = containers_api.create_container_and_version(
5150
learning_package_id,
5251
container_code=container_code,
53-
entity_ref=entity_ref,
5452
title=title,
5553
entities=components,
5654
created=created,

0 commit comments

Comments
 (0)