From f67060fd8fc07a46f20ee6cbb13468b60dd7abbc Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Wed, 29 Jan 2025 15:25:50 +0100 Subject: [PATCH] fix(backend): Fix get balance error on user with null running balance (#9365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Changes 🏗️ The current state can cause this error: ``` if (snapshot_time.year, snapshot_time.month) == (cur_time.year, cur_time.month): ^^^^^^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'year' ``` Which is caused by the timestamp return value possibly a string. ### Checklist 📋 #### For code changes: - [ ] I have clearly listed my changes in the PR description - [ ] I have made a test plan - [ ] I have tested my changes according to the test plan: - [ ] ...
Example test plan - [ ] Create from scratch and execute an agent with at least 3 blocks - [ ] Import an agent from file upload, and confirm it executes correctly - [ ] Upload agent to marketplace - [ ] Import an agent from marketplace and confirm it executes correctly - [ ] Edit an agent from monitor, and confirm it executes correctly
#### For configuration changes: - [ ] `.env.example` is updated or already compatible with my changes - [ ] `docker-compose.yml` is updated or already compatible with my changes - [ ] I have included a list of my configuration changes in the PR description (under **Changes**)
Examples of configuration changes - Changing ports - Adding new services that need to communicate with each other - Secrets or environment variable changes - New or infrastructure changes such as databases
--- autogpt_platform/backend/backend/data/credit.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autogpt_platform/backend/backend/data/credit.py b/autogpt_platform/backend/backend/data/credit.py index b4953eed29..5feb5f9292 100644 --- a/autogpt_platform/backend/backend/data/credit.py +++ b/autogpt_platform/backend/backend/data/credit.py @@ -132,12 +132,14 @@ class UserCreditBase(ABC): }, ) transaction_balance = ( - transactions[0].get("_sum", {}).get("amount", 0) + snapshot_balance + int(transactions[0].get("_sum", {}).get("amount", 0) + snapshot_balance) if transactions else snapshot_balance ) transaction_time = ( - transactions[0].get("_max", {}).get("createdAt", datetime_min) + datetime.fromisoformat( + str(transactions[0].get("_max", {}).get("createdAt", datetime_min)) + ) if transactions else snapshot_time )