-
Notifications
You must be signed in to change notification settings - Fork 18
Description
NOTE: This is not ready for work yet -- see the note at the bottom.
In a recent PR, there was a need for code like this:
current_draft: Optional[Draft] = getattr(entity, "draft", None)
current_published: Optional[Published] = getattr(entity, "published", None)This is because creating a new PublishableEntity does not populate these other models:
openedx-learning/openedx_learning/apps/authoring/publishing/api.py
Lines 183 to 205 in ae59743
| def create_publishable_entity( | |
| learning_package_id: int, | |
| /, | |
| key: str, | |
| created: datetime, | |
| # User ID who created this | |
| created_by: int | None, | |
| *, | |
| can_stand_alone: bool = True, | |
| ) -> PublishableEntity: | |
| """ | |
| Create a PublishableEntity. | |
| You'd typically want to call this right before creating your own content | |
| model that points to it. | |
| """ | |
| return PublishableEntity.objects.create( | |
| learning_package_id=learning_package_id, | |
| key=key, | |
| created=created, | |
| created_by_id=created_by, | |
| can_stand_alone=can_stand_alone, | |
| ) |
I think I originally wanted to distinguish between never published and published-but-since-unpublished. But now we have a whole PublishLog to track that.
Problem: The Published model actually has a non-nullable reference to a PublishLogRecord that points to how this particular version became the published version. If we initialize a Published entry to null, we would have to make this field nullable as well. Is that tradeoff worth it, or should we just make helpers on PublishableEntity to return the draft and published versions instead?