desk/services/reporters.py & desk/api/team.py: reporters.merge Raises UniqueViolationError When into.id < other.id and Payout Addresses Desynchronize Across Endpoints
Report
In desk/desk/services/reporters.py, desk/desk/services/sync.py, and desk/desk/api/team.py, interacting defects in reporter merging and payout-address propagation cause unhandled database IntegrityError crashes (HTTP 500), orphaned sessions, and silent loss/desynchronization of bounty payout addresses:
-
reporters.merge()triggers PostgreSQLUniqueViolationError(HTTP 500) onreporters.github_idwheninto.id < other.idand orphansReporterSessionrows (desk/desk/services/reporters.py:211-229,desk/desk/models.py:248):Reporter.github_idhas a non-deferrableUNIQUEconstraint (models.py:248). Inmerge(),into.github_id = into.github_id or other.github_idandother.github_id = Noneare dirtied in the same SQLAlchemy unit of work beforectx.events.append()callsawait db.flush(). Wheninto.id < other.idandinto.github_idwasNonewhileother.github_idwas set (e.g.,intowas created first via email/XE key andotherwas created later via GitHub OAuth, then linked intointo), SQLAlchemy flushesUPDATE reportersin primary-key order (intobeforeother), raisingUniqueViolationErroronreporters_github_id_key(HTTP 500). Wheninto.id > other.id,merge()leavesReporterSessionrows (reporter_sessions.reporter_id == other.id) pointing to the wiped"merged into ..."shell row, andfrom_xe()(lines 201-202) merges without checking for conflictinggithub_id/email/xe_address, silently wipingother's identity andpayout_proof. -
Ticket.payout_addressis dropped or left stale acrosssync.upsert_issue(),reporters.attach(),reporters.merge(), andreporters.bind_payout(), whileGET /v1/team/payoutsandGET /v1/team/payouts.csvdiverge (desk/desk/services/sync.py:86-100,desk/desk/services/reporters.py:101-144, 211-248, 422-452,desk/desk/api/team.py:286-305):
sync.upsert_issue()(sync.py:86-100) createsNewTicket(..., reporter_id=reporter.id if reporter else None)without passingpayout_address=reporter.xe_address, so every GitHub-synced issue filed by a reporter who already bound their payout address is created witht.payout_address = "".- Neither
reporters.attach()norreporters.merge()backfillsr.xe_address/into.xe_addressonto unpaid tickets witht.payout_address == "". reporters.bind_payout()(reporters.py:241-246) updatesr.xe_address = addressand overwritesr.payout_proof, but only updates tickets whereTicket.payout_address == "", leaving any unpaid ticket that had a previously bound address pointing to the stale address.GET /v1/team/payouts(team.py:286-305) returnst.payout_address(and omitsaward_approved_at.is_not(None)/award_xe.is_not(None)filters), whereasGET /v1/team/payouts.csv(reporters.py:422-452) returnsr.xe_addressand truncates sub-XE amounts via(t.award_xe or 0) // 1_000_000.
Remediation
- In
reporters.merge(), setother.github_id = Noneandawait db.flush()before settinginto.github_id, re-pointReporterSession.reporter_id == other.idtointo.id, and backfillt.payout_address = into.xe_addresson unpaid bounty tickets inmerge()andattach(). - Pass
payout_address=reporter.xe_address if reporter else ""insync.upsert_issue(), update all unpaid bounty tickets (Ticket.status != "paid") when re-binding inbind_payout(), and alignGET /v1/team/payoutswithreporters.payout_rows().
Thread
Thanks for the report. Part of what you describe was already on file from earlier reports (https://bounty.xe.network/XE-0710 and https://bounty.xe.network/XE-0711); the remaining point about the account-merge error is being looked at and we will update this ticket when there is more to say.