-
Notifications
You must be signed in to change notification settings - Fork 308
alexpott's balance doesn't add up to 0 #1633
Comments
I hypothesize that this will be the case for anyone whom we've Mass Paid. I believe there's a SQL query buried somewhere in the issue tracker to find out who is affected by a bug like this. We should dig that up, run that, and compare it to the list of people we've Mass Paid. |
I think it was more like ... select username, balance
from participants
where balance != (select sum(amount)
from exchanges
where participant = username); But that's timing out for me (on a local backup). |
Try this, its fast (150ms): select username, balance
from participants
where paypal_email is not null
and balance != (select sum(amount) from exchanges where participant =username); It runs only for 5 rows and not for 50k. Judging from the number of rows the full query should run for about 30 minutes. Maybe adding index on exchanges participant column could speed it up (now it does seq scan). I don't have my local setup at hand to test. |
Thanks @zwn. That's good enough for this ticket. |
Alright, what's going on here? |
I'm looking at this locally. I'm looking at SlappyBag instead of alexpott because Alex has tons more history, making his case harder to reason about. |
SlappyBag's current balance is 0.63. |
I believe the problem is in how fees are posted back to Gittip in step 3 of the Mass Pay flow. |
SlappyBag's balance is off by 2.98, and that is the sum of the fees for the two Mass Pays he's been involved with (2.35 + 0.63). |
I believe this is a bug in /%username/history/record-an-exchange.spt. There we update the user's balance based on the amount but ignore the fee. I think this is probably correct when the exchange is a credit card charge, but not when it is a bank account deposit. |
We've overpaid people. SlappyBag, for example. The buggy POST to record-an-exchange two weeks ago meant that SlappyBag had too high of a balance going into last week, so we paid him too much. |
So we've got to:
|
We weren't taking the fee out of the user's balance for payouts. This commit includes a note on the exchanges table in the new dev docs.
Okay, there's a fix in #1650 waiting to be merged. |
Now to repair the database ... |
We need to adjust balanced downward for those affected. Now is actually the ideal time to do that because we've run another payday so there should be enough for each user to take out the fee. Then we can proceed with Mass Pay as usual. |
Fix bug in record-an-exchange; #1633
So who all is affected? Anyone for whom we used record-an-exchange with a negative amount and a positive (non-zero) fee. |
Namely, |
Seven users are affected. |
I'm not seeing the numbers line up for the seven people affected. I expected to see balances on the history page be off by the amount of the fees from that last query. But in some cases they are, in others, not. |
Got it! |
We've done three Mass Pays: October 11, 24, and 31. It appears that only during the second two did we screw up and not take the payout fee out of the users' balances.
I'd like to see if I can dig up a reason why the bug wasn't in the first Mass Pay (we didn't use record-an-exchange, I guess?), and then I think we're in a position to adjust balances for the five users who participated in one or both of the bad Mass Pays. Adjusting these balances will take care of both db repair and overpayment recovery from #1633 (comment). |
Best I can find is #943 (comment) and #943 (comment). I would've used the admin UI on the history page to record those exchanges. I guess I manually updated their balances in the db at that point? That sounds vaguely familiar. Since we don't log balance changes (see #1549) I guess that's the closest we're going to get to the bottom of this. :-/ |
I've manually adjusted the balances for these users: @alexpott @evbogue @Higgo @nicferrier @SlappyBag. |
I believe this is now resolved and I can go run Mass Pay for this week! |
Overpayments due to this bug manifest as a negative balance on the history page for affected users. |
MassPay done for this week. Spot-checked a few accounts, looks good! |
His balance should subtract out to 0 at the bottom but it's 25.90. This has to be a bug in MassPay (#943).
The text was updated successfully, but these errors were encountered: