-
Notifications
You must be signed in to change notification settings - Fork 144
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
Reward point redemption events #2264
base: main
Are you sure you want to change the base?
Reward point redemption events #2264
Conversation
712cd29
to
51df256
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.
✔️ Meets requirements
✔️ UI functionality checked
form.set("form-0-points", 3) | ||
form.set("form-1-points", 3) |
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.
Are "0" and "1" here PKs of the corresponding events, or how do we later map this to events? (I feel like this mapping was lost from the previous post-params)
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.
There is always a corresponding form field like form-0-pk
that does the mapping.
evap/rewards/views.py
Outdated
total_points_available = reward_points_of_user(request.user) | ||
events = RewardPointRedemptionEvent.objects.filter(redeem_end_date__gte=datetime.now().date()).order_by("date") | ||
|
||
formset = RewardPointRedemptionFormSet( | ||
request.POST or None, | ||
initial=[{"event": e, "points": 0, "total_points_available": total_points_available} for e in events], | ||
user=request.user, | ||
) |
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.
problematic: total_points_available
is computed outside of the transaction/locked critical section, formset clean
is computed without database locking, and save
might run arbitrarily later -- with the possibility that the same points have been redeemed in between.
For this to be safe, we need to ensure that during the update path, all three steps (calculate limit, clean, save) are stored in the transaction while the rows are locked.
51df256
to
9743c64
Compare
Close #2258
Close #1825