Skip to content
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

Merged
merged 2 commits into from
Aug 16, 2024

Conversation

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Aug 7, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Aug 7, 2024

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If 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 @axim-engineering. Tag them in a comment and let them know that your changes are ready for review.

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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@ormsbee
Copy link
Contributor

ormsbee commented Aug 8, 2024

The mechanism that Learning Core uses to "delete" published things is to:

  1. Set the Draft version to be null (removes it from Studio, but not the published LMS version).
  2. The act of publishing then sets the Published version of that PublisahbleEntity to also be null, which makes it disappear from the LMS.

Wouldn't excluding soft-deleted drafts from the publish process break that?

@navinkarkera navinkarkera force-pushed the navin/fix-deleted-drafts-handling branch from 682f73d to bde3224 Compare August 9, 2024 14:54
@navinkarkera
Copy link
Contributor Author

@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!

@navinkarkera navinkarkera force-pushed the navin/fix-deleted-drafts-handling branch from bde3224 to 66f7327 Compare August 9, 2024 14:57
@navinkarkera navinkarkera changed the title fix: exclude deleted drafts while publishing fix: exclude deleted drafts while publishing [FAL-3797] Aug 12, 2024
@navinkarkera navinkarkera changed the title fix: exclude deleted drafts while publishing [FAL-3797] fix: exclude deleted drafts while publishing [FC-0062] Aug 12, 2024
@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Aug 12, 2024
@navinkarkera navinkarkera force-pushed the navin/fix-deleted-drafts-handling branch from 66f7327 to 0d13648 Compare August 13, 2024 10:21
Copy link
Contributor

@ChrisChV ChrisChV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@navinkarkera Looks good 👍

@bradenmacdonald
Copy link
Contributor

@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'))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@ormsbee ormsbee Aug 14, 2024

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.

@navinkarkera navinkarkera force-pushed the navin/fix-deleted-drafts-handling branch from 0d13648 to b971438 Compare August 14, 2024 11:02
@navinkarkera navinkarkera changed the title fix: exclude deleted drafts while publishing [FC-0062] feat: option to include deleted drafts while fetching unpublished entities [FC-0062] Aug 14, 2024
@navinkarkera navinkarkera force-pushed the navin/fix-deleted-drafts-handling branch from b971438 to fbf8862 Compare August 14, 2024 11:08
@navinkarkera navinkarkera force-pushed the navin/fix-deleted-drafts-handling branch from fbf8862 to 46da6c8 Compare August 14, 2024 15:22
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'))
Copy link
Contributor

@ormsbee ormsbee Aug 15, 2024

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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ormsbee Makes sense. Updated and included a test inspired by your PR: #211

@navinkarkera navinkarkera force-pushed the navin/fix-deleted-drafts-handling branch from dfe7691 to a893e84 Compare August 16, 2024 14:20
@navinkarkera navinkarkera requested a review from ormsbee August 16, 2024 14:25
@ormsbee
Copy link
Contributor

ormsbee commented Aug 16, 2024

@navinkarkera: Are you okay with me squashing and merging this now?

@ormsbee ormsbee merged commit 534316b into openedx:main Aug 16, 2024
9 checks passed
@openedx-webhooks
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants