-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: transaction operations with UUID not updating balances correctly… #559
fix: transaction operations with UUID not updating balances correctly… #559
Conversation
…… 🐛 🐛 This commit resolves issues with transactions using account UUIDs instead of aliases: 1. Fixed account matching in transaction operations: - Enhanced account lookup to match by both balance.ID and balance.AccountID - Simplified the string comparison logic with direct UUID comparisons - Improved logging to show which field (ID or AccountID) matched 2. Fixed balance update logic for UUID-based accounts: - Modified SelectForUpdate in balance.postgresql.go to support UUIDs - Enhanced query to search for account_id and id in a single query - Added key lookup strategy in balance update function to find the correct entry in fromTo map by either alias, balance.ID or balance.AccountID The issue was caused by account references not being properly matched during transaction processing. UUIDs in the request body were not being mapped to the correct balance record in the database during the balance update phase. This fix ensures operations are created and balances are updated correctly regardless of whether accounts are referenced by UUID or alias. Co-Authored-By: Hugo Aguiar Martinez <2437999+MartinezAvellan@users.noreply.github.com> Co-Authored-By: Felipe Gomes <178956569+gitfelipegomes@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Overview
This PR fixes issues with transaction operations using UUIDs by improving account matching and balance update logic. Key changes include:
- Enhancing account lookup queries to match by both alias and UUID fields.
- Refactoring the SelectForUpdate function to handle both aliases and accountIDs using a combined query.
- Updating related services, mocks, and validations to support the new UUID-based logic.
Reviewed Changes
File | Description |
---|---|
components/transaction/internal/adapters/postgres/balance/balance.postgresql.go | Updated query in ListByAccountIDs and enhanced SelectForUpdate to handle both aliases and accountIDs. |
components/transaction/internal/services/command/create-operation.go | Modified account matching logic to support UUID comparisons with detailed logging. |
components/transaction/internal/adapters/http/in/transaction.go | Adjusted account comparison for UUIDs with improved log messages. |
pkg/gold/transaction/model/validations.go | Revised UUID comparison in validations and updated Scale function comments. |
components/transaction/internal/services/query/get-balances.go | Added debug logging for UUIDs and aliases during balance retrieval. |
components/transaction/internal/services/command/update-balance.go | Extracted UUIDs and aliases separately before updating balances using the new repository signature. |
components/transaction/internal/adapters/postgres/balance/balance.mock.go | Updated mock definitions to match the new SelectForUpdate interface signature. |
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
components/transaction/internal/adapters/postgres/balance/balance.postgresql.go:628
- [nitpick] Consider refactoring the repeated UUID matching logic into a helper function to improve code readability and maintainability.
if pkg.IsUUID(balance.ID) {
components/transaction/internal/services/command/create-operation.go:35
- [nitpick] Consider consolidating the UUID and alias comparison logic into a single utility function to reduce duplicated logic in account matching.
if fromTo[i].Account == blc.ID || fromTo[i].Account == blc.Alias {
components/transaction/internal/adapters/postgres/balance/balance.mock.go
Show resolved
Hide resolved
1. ✓ Fixed the interface{} to any conversion in balance.postgresql.go 2. ✓ Added proper spacing between conditionals and for loops in get-balances.go 3. ✓ Fixed the nested if-statements in transaction.go 4. ✓ Fixed declaration cuddling issue in balance.postgresql.go by properly declaring the error variable before assignment
…… 🐛 🐛
This PR resolves issues with transactions using account UUIDs instead of aliases:
Fixed account matching in transaction operations: - Enhanced account lookup to match by both balance.ID and balance.AccountID - Simplified the string comparison logic with direct UUID comparisons - Improved logging to show which field (ID or AccountID) matched
Fixed balance update logic for UUID-based accounts: - Modified SelectForUpdate in balance.postgresql.go to support UUIDs - Enhanced query to search for account_id and id in a single query - Added key lookup strategy in balance update function to find the correct entry in fromTo map by either alias, balance.ID or balance.AccountID
The issue was caused by account references not being correctly matched during transaction processing. UUIDs in the request body were not mapped to the correct balance record in the database during the balance update phase.
This fix ensures operations are created and balances are updated correctly regardless of whether accounts are referenced by UUID or alias.
Midaz Pull Request Checklist
Pull Request Type
Checklist
Please check each item after it's completed.
Obs: Please, always remember to target your PR to develop branch instead of main.
Additional Notes