Skip to content

Fix staking refresh to ensure balance updates are applied#216

Merged
nomadicrogue merged 2 commits into
testfrom
dev
Mar 6, 2026
Merged

Fix staking refresh to ensure balance updates are applied#216
nomadicrogue merged 2 commits into
testfrom
dev

Conversation

@nomadicrogue
Copy link
Copy Markdown
Collaborator

No description provided.

nomadicrogue and others added 2 commits March 6, 2026 10:50
The daily staking refresh cron was writing ledger entries but failing to
update credit_account_balances for some users (e.g. user 352). Root cause
was two compounding issues:

1. get_or_create_balance() was called without for_update=True, so a Redis
   cache hit returned a detached ORM object not tracked by the SQLAlchemy
   session. Modifying it and calling db.commit() was a silent no-op for
   the balance row.

2. create_ledger_entry() used auto_commit=True (default), committing the
   ledger row in its own transaction. If anything failed before the
   subsequent balance commit, the ledger entry persisted while the balance
   rollback left staking_daily_amount/staking_available at zero.

Fix: use for_update=True to always get a session-managed row from the DB
(bypassing cache), and auto_commit=False so the ledger entry and balance
update are committed in a single atomic transaction.

Made-with: Cursor
…-balance

fix: prevent staking refresh from silently losing balance updates
@nomadicrogue nomadicrogue merged commit d48e03f into test Mar 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant