File tree Expand file tree Collapse file tree
src/openedx_content/applets/publishing
tests/openedx_content/applets/publishing Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -932,6 +932,15 @@ def set_draft_version(
932932 # block is bookkeeping in our DraftChangeLog.
933933 draft .version_id = publishable_entity_version_pk
934934
935+ # Validate the entity
936+ if publishable_entity_version_pk is not None :
937+ if draft .entity .id != PublishableEntityVersion .objects .only ("entity_id" ).get (
938+ pk = publishable_entity_version_pk
939+ ).entity_id :
940+ raise ValidationError (
941+ "Entity mismatch - the specified PublishableEntityVersion does not match the PublishableEntity"
942+ )
943+
935944 # Check to see if we're inside a context manager for an active
936945 # DraftChangeLog (i.e. what happens if the caller is using the public
937946 # bulk_draft_changes_for() API call), or if we have to make our own.
Original file line number Diff line number Diff line change @@ -2440,7 +2440,7 @@ def test_set_draft_version_rejects_version_from_different_entity(self) -> None:
24402440 # This should raise an error because version_b_v1 belongs to entity_b,
24412441 # not entity_a. Without validation, this silently corrupts entity_a's
24422442 # draft to point to entity_b's content.
2443- with pytest .raises (( ValidationError , ValueError ) ):
2443+ with pytest .raises (ValidationError , match = "Entity mismatch" ):
24442444 publishing_api .set_draft_version (entity_a .id , version_b_v1 .pk )
24452445
24462446 def test_publish_from_drafts_rejects_cross_package_drafts (self ) -> None :
You can’t perform that action at this time.
0 commit comments