Skip to content

refactor(badges): prevent orphaned BadgeProgress creation#2989

Draft
luisfelipec95 wants to merge 1 commit into
openedx:masterfrom
Pearson-Advance:lfc/prevent-orphan-badge-progress
Draft

refactor(badges): prevent orphaned BadgeProgress creation#2989
luisfelipec95 wants to merge 1 commit into
openedx:masterfrom
Pearson-Advance:lfc/prevent-orphan-badge-progress

Conversation

@luisfelipec95

Copy link
Copy Markdown
Contributor

Description

The badge processing system is creating an excessive number of orphaned BadgeProgress records (records without associated Fulfillment data) due to a critical logic flaw. With 140+ active badge templates, this issue is significantly amplified, creating thousands of unnecessary database records daily.

Changes

An optional create parameter (default True) was added to the for_user() method. This parameter controls whether the method should create a new BadgeProgress record when it doesn't exist, or simply retrieve it if it already exists.

Previously, the method always created a record using get_or_create(), with no option to just query. This meant any code that called this method, even just to check if a record existed, would end up automatically creating one.

How to test

  1. Configure Badge Template:

    • Navigate to the badge template admin panel
    • Enable "Is active" checkbox
    • In Badge requirements section, add an EVENT_TYPE:
      • org.openedx.learning.course.passing.status.updated.v1
      • org.openedx.learning.ccx.course.passing.status.updated.v1
  2. Create Badge Requirements:

    • Go to Badge requirement admin panel
    • Add Data rules for the requirement (e.g., is_passing = true)
  3. Create a test course in Studio:

    • Create a new course with grading enabled
    • Add a subsection with grading enabled
    • Add a problem worth points that leads to passing grade
    • Enroll and complete course:
  4. Enroll test student in course

    • Answer problems to meet passing grade
    • Verify "Passing" status is displayed

Before the changes

At the time of testing, there are 8 active badge templates, of which only 4 meet the rules for a completed course, yet 8 badgeProgress records are generated.

image

After the changes

It only creates in badgeProgress the necessary records—those that meet the badge template rules.

image

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jun 1, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @luisfelipec95!

This repository is currently maintained by @jajjibhai008.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are 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.

🔘 Update the status of your PR

Your PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate.


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: No status
Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

3 participants