You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After voting once on an off-chain proposal, attempting to change the vote a second time results in an error. This happens in both production and the deploy preview, so it's not related to PR #35.
Steps to Reproduce
Create or find an off-chain proposal with XTZ-weighted voting
Vote on a choice
Change your vote to a different choice - this works
Try to change your vote again
Error is thrown
[Screenshot: Error message in console]
Error Details
Error message:
Error: Cannot read properties of null (reading 'walletAddresses')
Backend logs:
[choices.update:tz:error] {
reqId: 'mi2xgcrv-kiidwm',
error: "Cannot read properties of null (reading 'walletAddresses')",
stack: "TypeError: Cannot read properties of null (reading 'walletAddresses')\n" +
' at updateChoiceById (C:\\code\\homebase-lite-backend\\components\\choices\\index.js:265:45)\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:105:5)'
}
Root Cause
In components/choices/index.js around line 262-265:
if(isVoted.length>0){constoldVoteObj=isVoted[0].walletAddresses.find(x=>x.address===address);oldVote=awaitChoiceModel.findById(oldVoteObj.choiceId);constoldSignaturePayload=oldVote.walletAddresses[0].payloadBytes// <-- oldVote is null!
The code tries to find the old vote's choice document, but findById returns null when the choice document doesn't exist. This happens when there's a database inconsistency where the vote reference exists but the actual choice document was deleted or is missing.
Impact
Users can only change their vote once
After the first change, they're stuck with that choice
This affects user experience on longer voting periods where opinions might change
The issue appears to be related to orphaned choice references in the database
Needs null check before accessing oldVote.walletAddresses
Suggested Fix
Add a null check:
if(isVoted.length>0){constoldVoteObj=isVoted[0].walletAddresses.find(x=>x.address===address);oldVote=awaitChoiceModel.findById(oldVoteObj.choiceId);if(!oldVote){thrownewError('Previous vote choice not found - database inconsistency');}constoldSignaturePayload=oldVote.walletAddresses[0].payloadBytes// ... rest of the logic}
Though this might just surface the underlying database inconsistency issue. May need to investigate why choice documents are getting deleted or not created properly.
After voting once on an off-chain proposal, attempting to change the vote a second time results in an error. This happens in both production and the deploy preview, so it's not related to PR #35.
Steps to Reproduce
[Screenshot: Error message in console]
Error Details
Error message:
Backend logs:
Root Cause
In
components/choices/index.jsaround line 262-265:The code tries to find the old vote's choice document, but
findByIdreturnsnullwhen the choice document doesn't exist. This happens when there's a database inconsistency where the vote reference exists but the actual choice document was deleted or is missing.Impact
Notes
oldVote.walletAddressesSuggested Fix
Add a null check:
Though this might just surface the underlying database inconsistency issue. May need to investigate why choice documents are getting deleted or not created properly.