fix(billing): register synckey parent for transaction entities#5
Merged
Conversation
Transaction entities must have a parent key (synckey/1) for ancestor queries in the billing balance calculation. The parent was set in transaction.New() but lost during ORM key allocation because the mixin's Parent field didn't propagate to the ORM's internal parent. Register a ParentFn via orm.WithParent so the ORM always sets the correct parent key when allocating transaction entity keys.
hanzo-dev
pushed a commit
that referenced
this pull request
May 13, 2026
Transaction entities must have a parent key (synckey/1) for ancestor queries in the billing balance calculation. The parent was set in transaction.New() but lost during ORM key allocation because the mixin's Parent field didn't propagate to the ORM's internal parent. Register a ParentFn via orm.WithParent so the ORM always sets the correct parent key when allocating transaction entity keys.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
orm.WithParenton the Transaction modelParentfield (set intransaction.New()) wasn't propagating to the ORM's internalparentfield during key allocationKey()method checksmeta.ParentFnto set parent — without it, transactions get nil parent, soparent_idis NULL in SQLite, and ancestor queries (WHERE parent_id = '1') return nothingContext
PR #4 fixed the
ON CONFLICTclause to preserveparent_idon upsert, but the root cause was thatparent_idwas never set on INSERT. This PR fixes the INSERT path by ensuring the ORM always allocates transaction keys with the correct parent.Test plan
GET /api/v1/billing/balanceshows correct amount