Skip to content

Commit

Permalink
fix(backend): Fix get balance error on user with null running balance (
Browse files Browse the repository at this point in the history
…#9365)

### 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:
  <!-- Put your test plan here: -->
  - [ ] ...

<details>
  <summary>Example test plan</summary>
  
  - [ ] 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
</details>

#### 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**)

<details>
  <summary>Examples of configuration changes</summary>

  - Changing ports
  - Adding new services that need to communicate with each other
  - Secrets or environment variable changes
  - New or infrastructure changes such as databases
</details>
  • Loading branch information
majdyz authored Jan 29, 2025
1 parent c31a2ec commit f67060f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions autogpt_platform/backend/backend/data/credit.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@ async def _get_credits(self, user_id: str) -> tuple[int, datetime]:
},
)
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
)
Expand Down

0 comments on commit f67060f

Please sign in to comment.