Skip to content

Diya 🔥 fix(bs): Fixed Blue Square Deletion Issue#2200

Merged
one-community merged 1 commit into
developmentfrom
Diya_Fix_BSDeletion
May 7, 2026
Merged

Diya 🔥 fix(bs): Fixed Blue Square Deletion Issue#2200
one-community merged 1 commit into
developmentfrom
Diya_Fix_BSDeletion

Conversation

@DiyaWadhwani
Copy link
Copy Markdown
Contributor

Description

Fixes a race condition where manually adding a blue square on Sunday overwrites the cron-assigned blue square issued at midnight. The bug occurred because addInfringements used findById + record.save() which fetched a stale snapshot of the document before the cron's $push completed, then overwrote the entire infringements array on save.

Fixes: Blue square race condition — manually added blue square deletes cron-assigned blue square on Sunday

Related PRs (if any):

N/A — backend only fix.

Main changes explained:

  • Updated src/controllers/userProfileController.js addInfringements function to replace record.infringements = ...; record.save() with findByIdAndUpdate using $push so the new infringement is added atomically without overwriting any other infringements added between the findById and save calls

How to test:

  1. Check out current branch
  2. Run npm install and npm run dev
  3. Trigger the cron job manually or simulate it by calling assignBlueSquareForTimeNotMet directly
  4. Immediately after, manually add a blue square via the UI for the same user
  5. Verify both blue squares are present after refresh
  6. Verify only the new infringement is added, not duplicated

Note:

This is a race condition specific to Sunday when the cron runs at midnight. The cron uses $push atomically but the manual controller was doing a read-modify-write which could lose the cron's update if both operations overlapped.

@one-community one-community added the High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible label May 7, 2026
@one-community one-community changed the title Diya fix(bs): Fixed Blue Square Deletion Issue Diya 🔥 fix(bs): Fixed Blue Square Deletion Issue May 7, 2026
@one-community one-community merged commit 91d82ff into development May 7, 2026
2 checks passed
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 7, 2026

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

Labels

High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants