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

Reward point redemption events #2264

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hansegucker
Copy link
Collaborator

Close #2258
Close #1825

evap/rewards/forms.py Outdated Show resolved Hide resolved
evap/rewards/forms.py Outdated Show resolved Hide resolved
evap/rewards/templates/rewards_index.html Outdated Show resolved Hide resolved
evap/rewards/forms.py Outdated Show resolved Hide resolved
evap/rewards/views.py Outdated Show resolved Hide resolved
evap/rewards/forms.py Outdated Show resolved Hide resolved
@hansegucker hansegucker force-pushed the reward-point-redemption-events branch 2 times, most recently from 712cd29 to 51df256 Compare August 12, 2024 18:39
Copy link
Member

@janno42 janno42 left a 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

Comment on lines +69 to +70
form.set("form-0-points", 3)
form.set("form-1-points", 3)
Copy link
Member

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)

Copy link
Collaborator Author

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/tests/test_views.py Outdated Show resolved Hide resolved
Comment on lines 35 to 42
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,
)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants