Skip to content

Commit

Permalink
fix(backend): Make sure all the obtained DB connections are able to q…
Browse files Browse the repository at this point in the history
…uery (#8894)

### Changes 🏗️

We've seen some symptoms where during the initial startup of the
application the obtained db connection produces an error when the
network is unreachable. This code made sure that the obtained connection
could run the query and retry it on the spot if it was unable to do so.

### 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 Dec 6, 2024
1 parent 6dba31e commit e290413
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autogpt_platform/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,4 @@ To add a new agent block, you need to create a new class that inherits from `Blo
* `run` method: the main logic of the block.
* `test_input` & `test_output`: the sample input and output data for the block, which will be used to auto-test the block.
* You can mock the functions declared in the block using the `test_mock` field for your unit tests.
* Once you finish creating the block, you can test it by running `pytest -s test/block/test_block.py`.
* Once you finish creating the block, you can test it by running `poetry run pytest -s test/block/test_block.py`.
7 changes: 7 additions & 0 deletions autogpt_platform/backend/backend/data/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ async def connect():
if not prisma.is_connected():
raise ConnectionError("Failed to connect to Prisma.")

# Connection acquired from a pool like Supabase somehow still possibly allows
# the db client obtains a connection but still reject query connection afterward.
try:
await prisma.execute_raw("SELECT 1")
except Exception as e:
raise ConnectionError("Failed to connect to Prisma.") from e


@conn_retry("Prisma", "Releasing connection")
async def disconnect():
Expand Down

0 comments on commit e290413

Please sign in to comment.