-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: option to include deleted drafts while fetching unpublished entities [FC-0062] #207
feat: option to include deleted drafts while fetching unpublished entities [FC-0062] #207
Conversation
Thanks for the pull request, @navinkarkera! What's next?Please work through the following steps to get your changes ready for engineering review: 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Let us know that your PR is ready for review:Who will review my changes?This repository is currently maintained by Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:
When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
The mechanism that Learning Core uses to "delete" published things is to:
Wouldn't excluding soft-deleted drafts from the publish process break that? |
682f73d
to
bde3224
Compare
@ormsbee Ahh yes, that change is not really required. Thank you for pointing it out, I missed to remove it and test once I got around fixing the meilisearch caching. Updated! |
bde3224
to
66f7327
Compare
66f7327
to
0d13648
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@navinkarkera Looks good 👍
- I tested this: I followed the testing instructions on fix: discard changes [FC-0062] open-craft/frontend-app-authoring#58 (review)
- I read through the code and considered the security, stability and performance implications of the changes.
@ormsbee Are you OK with this PR now? |
.filter( | ||
learning_package_id=learning_package_id, | ||
draft__version__isnull=False, | ||
).exclude(draft__version=F('published__version')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a docstring explaining this behavior (that it omits the entities that were soft-deleted), or make it a keyword argument. Otherwise, I'm fine with this.
Question that this brought to mind (doesn't have to be part of this PR): Does publish_all_drafts have a bug where it's re-publishing soft-deletes over and over again because NULL != NULL in SQL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a docstring explaining this behavior (that it omits the entities that were soft-deleted), or make it a keyword argument. Otherwise, I'm fine with this.
Done.
Question that this brought to mind (doesn't have to be part of this PR): Does publish_all_drafts have a bug where it's re-publishing soft-deletes over and over again because NULL != NULL in SQL?
Yes, it does re-publish it over and over again. We probably need to use a specific value in version field like -1
for soft-deletes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can stop the duplicate publishing by excluding Draft versions that are null where the matching Published version is also null, without resorting to special version field values. I'll make a PR for it.
0d13648
to
b971438
Compare
b971438
to
fbf8862
Compare
…ities By default, this is set to False.
fbf8862
to
46da6c8
Compare
query_filters = {"learning_package_id": learning_package_id} | ||
if not include_deleted_drafts: | ||
query_filters['draft__version__isnull'] = False | ||
return PublishableEntity.objects.filter(**query_filters).exclude(draft__version=F('published__version')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will erroneously return soft-deleted entries that have already been published, because of the NULL comparisons. I think that if we're making this flag, it needs to be something like:
entities_qs = (
PublishableEntity.objects
.filter(learning_package_id=learning_package_id)
.exclude(draft__version=F('published__version'))
)
if include_deleted_drafts:
# This means that we should also return PublishableEntities where the draft
# has been soft-deleted, but that deletion has not been published yet. Just
# excluding records where the Draft and Published versions don't match won't
# be enough here, because that will return soft-deletes that have already
# been published (since NULL != NULL in SQL).
#
# So we explicitly exclude already-published soft-deletes:
return entities_qs.exclude(
Q(draft__version__isnull=True) & Q(published__version__isnull=True)
)
# Simple case: exclude all entities that have been soft-deleted.
return entities_qs.exclude(draft__version__isnull=True)
(I had to deal with this in #211, which I'd love to get a review of if you have a moment.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dfe7691
to
a893e84
Compare
@navinkarkera: Are you okay with me squashing and merging this now? |
@navinkarkera 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
Related PRs and issues:
fix: discard changes [FC-0062] open-craft/frontend-app-authoring#58fix: discard button [FC-0062] frontend-app-authoring#1214