Skip to content

Commit 5f04fb4

Browse files
chore: use .id instead of .pk
1 parent 829c1e1 commit 5f04fb4

8 files changed

Lines changed: 27 additions & 19 deletions

File tree

cms/djangoapps/modulestore_migrator/tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,21 +345,21 @@ def _import_structure(
345345
used_component_keys=set(
346346
LibraryUsageLocatorV2(target_library.key, block_type, block_id) # type: ignore[abstract]
347347
for block_type, block_id
348-
in content_api.get_components(migration.target.pk).values_list(
348+
in content_api.get_components(migration.target.id).values_list(
349349
"component_type__name", "local_key"
350350
)
351351
),
352352
used_container_slugs=set(
353353
content_api.get_containers(
354-
migration.target.pk
354+
migration.target.id
355355
).values_list("publishable_entity__key", flat=True)
356356
),
357357
previous_block_migrations=(
358358
get_migration_blocks(source_data.previous_migration.pk)
359359
if source_data.previous_migration
360360
else {}
361361
),
362-
target_package_id=migration.target.pk,
362+
target_package_id=migration.target.id,
363363
target_library_key=target_library.key,
364364
source_context_key=source_data.source_root_usage_key.course_key,
365365
content_by_filename=content_by_filename,

cms/pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ filterwarnings =
1717
# ABC deprecation Warning comes from libsass
1818
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated.*:DeprecationWarning:sass
1919
ignore:'etree' is deprecated. Use 'xml.etree.ElementTree' instead.:DeprecationWarning:wiki
20+
# We sometimes use DeprecationWarning to enourage `.id` instead of `.pk` since there are some cases where we cannot
21+
# override the type of `.pk`, but we can always customize `.id` (e.g. using TypedBigAutoField). But we don't want to
22+
# see those warnings when Django is using `.pk` internally, which is fine.
23+
ignore:Use \.id instead:DeprecationWarning:django\..*
2024

2125
norecursedirs = envs
2226
python_classes =

openedx/core/djangoapps/content_libraries/api/blocks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def set_library_block_olx(usage_key: LibraryUsageLocatorV2, new_olx_str: str) ->
244244
created=now,
245245
)
246246
new_component_version = content_api.create_next_component_version(
247-
component.pk,
247+
component.id,
248248
title=new_title,
249249
media_to_replace={
250250
'block.xml': new_content.pk,
@@ -728,7 +728,7 @@ def send_block_deleted_signal():
728728
affected_collections = content_api.get_entity_collections(component.learning_package_id, component.key)
729729
affected_containers = get_containers_contains_item(usage_key)
730730

731-
content_api.soft_delete_draft(component.pk, deleted_by=user_id)
731+
content_api.soft_delete_draft(component.id, deleted_by=user_id)
732732

733733
send_block_deleted_signal()
734734

@@ -774,7 +774,7 @@ def restore_library_block(usage_key: LibraryUsageLocatorV2, user_id: int | None
774774

775775
# Set draft version back to the latest available component version id.
776776
content_api.set_draft_version(
777-
component.pk,
777+
component.id,
778778
component.versioning.latest.pk,
779779
set_by=user_id,
780780
)
@@ -910,7 +910,7 @@ def add_library_block_static_asset_file(
910910

911911
with transaction.atomic():
912912
component_version = content_api.create_next_component_version(
913-
component.pk,
913+
component.id,
914914
media_to_replace={file_path: file_content},
915915
created=datetime.now(tz=timezone.utc), # noqa: UP017
916916
created_by=user.id if user else None,
@@ -957,8 +957,8 @@ def delete_library_block_static_asset_file(usage_key, file_path, user=None):
957957
now = datetime.now(tz=timezone.utc) # noqa: UP017
958958

959959
with transaction.atomic():
960-
component_version = content_api.create_next_component_version( # noqa: F841
961-
component.pk,
960+
content_api.create_next_component_version(
961+
component.id,
962962
media_to_replace={file_path: None},
963963
created=now,
964964
created_by=user.id if user else None,

openedx/core/djangoapps/content_libraries/api/container_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def from_container(cls, library_key, container: Container, associated_collection
110110
published_by=published_by,
111111
last_draft_created=last_draft_created,
112112
last_draft_created_by=last_draft_created_by,
113-
has_unpublished_changes=content_api.contains_unpublished_changes(container.pk),
113+
has_unpublished_changes=content_api.contains_unpublished_changes(container.id),
114114
tags_count=tags.get(str(container_key), 0),
115115
collections=associated_collections or [],
116116
)
@@ -260,7 +260,7 @@ def _get_containers_with_entities(
260260
for member in members:
261261
qs = qs.union(
262262
content_api.get_containers_with_entity(
263-
member.entity.pk,
263+
member.entity.id,
264264
ignore_pinned=ignore_pinned,
265265
)
266266
)
@@ -338,7 +338,7 @@ def create(
338338
container=entity,
339339
),
340340
display_name=entity.versioning.draft.title,
341-
has_unpublished_changes=content_api.contains_unpublished_changes(entity.pk),
341+
has_unpublished_changes=content_api.contains_unpublished_changes(entity.id),
342342
container=entity,
343343
component=None,
344344
)

openedx/core/djangoapps/content_libraries/api/containers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def send_container_deleted_signal():
234234
container_key,
235235
published=False,
236236
)
237-
content_api.soft_delete_draft(container.pk)
237+
content_api.soft_delete_draft(container.id)
238238

239239
send_container_deleted_signal()
240240

@@ -294,7 +294,7 @@ def restore_container(container_key: LibraryContainerLocator) -> None:
294294
container.key,
295295
)
296296

297-
content_api.set_draft_version(container.pk, container.versioning.latest.pk)
297+
content_api.set_draft_version(container.id, container.versioning.latest.pk)
298298
# Fetch related containers after restore
299299
affected_containers = get_containers_contains_item(container_key)
300300
# Get children containers or components to update their index data
@@ -441,7 +441,7 @@ def get_containers_contains_item(key: LibraryUsageLocatorV2 | LibraryContainerLo
441441
[ 🛑 UNSTABLE ] Get containers that contains the item, that can be a component or another container.
442442
"""
443443
entity = get_entity_from_key(key)
444-
containers = content_api.get_containers_with_entity(entity.pk).select_related("container_type")
444+
containers = content_api.get_containers_with_entity(entity.id).select_related("container_type")
445445
return [ContainerMetadata.from_container(key.lib_key, container) for container in containers]
446446

447447

@@ -460,7 +460,7 @@ def publish_container_changes(
460460
learning_package = content_library.learning_package
461461
assert learning_package
462462
# The core publishing API is based on draft objects, so find the draft that corresponds to this container:
463-
drafts_to_publish = content_api.get_all_drafts(learning_package.id).filter(entity__pk=container.pk)
463+
drafts_to_publish = content_api.get_all_drafts(learning_package.id).filter(entity__pk=container.id)
464464
# Publish the container, which will also auto-publish any unpublished child components:
465465
publish_log = content_api.publish_from_drafts(
466466
learning_package.id,

openedx/core/djangoapps/content_libraries/api/libraries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def get_library(library_key: LibraryLocatorV2) -> ContentLibraryMetadata:
410410
license=ref.license,
411411
created=learning_package.created,
412412
updated=learning_package.updated,
413-
learning_package_id=learning_package.pk,
413+
learning_package_id=learning_package.id,
414414
)
415415

416416

@@ -494,7 +494,7 @@ def create_library(
494494
allow_public_learning=ref.allow_public_learning,
495495
allow_public_read=ref.allow_public_read,
496496
license=library_license,
497-
learning_package_id=ref.learning_package.pk, # type: ignore[union-attr]
497+
learning_package_id=ref.learning_package.id, # type: ignore[union-attr]
498498
)
499499

500500

openedx/core/djangoapps/xblock/runtime/openedx_content_runtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def save_block(self, block):
302302
created=now,
303303
)
304304
content_api.create_next_component_version(
305-
component.pk,
305+
component.id,
306306
title=block.display_name,
307307
media_to_replace={
308308
"block.xml": media.id,

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ filterwarnings = [
199199
# ABC deprecation Warning comes from libsass
200200
"ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated.*:DeprecationWarning:sass",
201201
"ignore:'etree' is deprecated. Use 'xml.etree.ElementTree' instead.:DeprecationWarning:wiki",
202+
# We sometimes use DeprecationWarning to enourage `.id` instead of `.pk` since there are some cases where we cannot
203+
# override the type of `.pk`, but we can always customize `.id` (e.g. using TypedBigAutoField). But we don't want to
204+
# see those warnings when Django is using `.pk` internally, which is fine.
205+
"ignore:Use \\.id instead:DeprecationWarning:django\\..*",
202206
]
203207
junit_family = "xunit2"
204208
norecursedirs = ". .* *.egg build conf dist node_modules test_root cms/envs lms/envs openedx/envs"

0 commit comments

Comments
 (0)