fix(polls): race condition problems issues #1995
Merged
nikkothari22 merged 11 commits intoJan 18, 2026
Merged
Conversation
… select polls and same poll same option same user problem
nikkothari22
approved these changes
Jan 18, 2026
| parent?: string | ||
| parentfield?: string | ||
| parenttype?: string | ||
| idx?: number |
Member
There was a problem hiding this comment.
@prathameshkurunkar7 Looks like frappe-types isn't adding option here right? The doctype has the field though. So weird.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Polls Race Condition: Prevent Duplicate Votes
Problem
Users could cast multiple votes in single-select polls due to race condition issue:
Issue #1: Same Option Multiple Times by same user on same poll
User clicks same option rapidly → Multiple vote records created for identical choice
This issue can be seen in #1908
Issue #2: Multiple Options in Single-Select Poll by same user
User rapidly clicks different options → Both votes registered in single-select poll
Root Cause: No database-level uniqueness enforcement. Application checks and inserts were separate operations, allowing concurrent requests to slip through.
Solution
Restructured from flat table to parent-child model with
UNIQUE(poll_id, user_id)constraint.Before (Flat Structure)
After (Parent-Child Structure)
Database enforces: One vote per user per poll. Race conditions now fail at DB level.
Changes
Backend
Raven Poll Vote Selection(child table for selected options)add_vote(),get_poll(),get_all_votes()- same structure - different operations internallybefore_insert(), counting from child table inupdate_poll_votes()UNIQUE(poll_id, user_id)onRaven Poll VoteMigration
optiondata to child tableRaven Poll Vote Selectionfrappe.flags.in_installto only apply the unique constraint directly on fresh site install. Else it would be applied via patch.Testing
Verified results on latest backup of prod.