Getting `AssertionError: DatabaseBackend is not running` for Postgres
See original GitHub issueIssue Description
Describe the bug I used the sample code from README to connect to a sqlite DB and query items and it worked fine (See https://github.com/mei-li/tsougkrizo/blob/persistency/persistence.py). When I switched to a Postgres DB the schema initialisation worked, but when I query the items I get:
File "./main.py", line 139, in websocket_host
game = await game_manager.get_game(game_id)
File "./main.py", line 82, in get_game
game = await Game.objects.get(uuid=game_id)
File "/home/olkos/.pyenv/versions/3.8.2/envs/tsougkrizo/lib/python3.8/site-packages/ormar/queryset/queryset.py", line 829, in get
return await self.filter(*args, **kwargs).get()
File "/home/olkos/.pyenv/versions/3.8.2/envs/tsougkrizo/lib/python3.8/site-packages/ormar/queryset/queryset.py", line 845, in get
rows = await self.database.fetch_all(expr)
File "/home/olkos/.pyenv/versions/3.8.2/envs/tsougkrizo/lib/python3.8/site-packages/databases/core.py", line 139, in fetch_all
async with self.connection() as connection:
File "/home/olkos/.pyenv/versions/3.8.2/envs/tsougkrizo/lib/python3.8/site-packages/databases/core.py", line 219, in __aenter__
await self._connection.acquire()
File "/home/olkos/.pyenv/versions/3.8.2/envs/tsougkrizo/lib/python3.8/site-packages/databases/backends/postgres.py", line 148, in acquire
assert self._database._pool is not None, "DatabaseBackend is not running"
AssertionError: DatabaseBackend is not running
To Reproduce Steps to reproduce the behavior:
- Go to https://github.com/mei-li/tsougkrizo/tree/persistency (only persistence.py and the sample url
/demo_ormar_issue
in main.py matter) - Create and install environment of the project with python 3.8
- Export an existing postgres DB url eg.
export DATABASE_URL=postgresql://dev:test@localhost/egg_db
- Run
python create_db.py
# this works and creates the DB schema - Run uvicorn main:app --reload
- Click on http://127.0.0.1:8000/demo_ormar_issue
- See error
(Note: this should be a complete and concise piece of code that allows reproduction of an issue)
Expected behavior I expect the query to objects in the DB to work without this error
Versions (please complete the following information):
- Database backend used (mysql/sqlite/postgress)
- Python version 3.8.2
ormar
version 0.10.4pydantic
version 1.8- if applicable
fastapi
version 0.54.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
AssertionError: DatabaseBackend is not running
So I have tried this: import databases @app.post("/computers/", response_model=Computer) async def create_computer(computer: ComputerIn): ...
Read more >tiangolo/fastapi - Gitter
Need help! Anybody got the issue about AssertionError: DatabaseBackend is not running? I encountered this problem when I use testClient for unit testing....
Read more >Database Backend Is Not Running - Nagios Support
Commercial Support Clients: Clients with support contracts can get escalated support assistance by visiting Nagios Answer Hub. These forums are ...
Read more >Testing a Database - FastAPI
... client.get(f"/users/{user_id}") assert response.status_code == 200, response.text data = response.json() assert data["email"] == "deadpool@example.com" ...
Read more >[Solved]-'django.db.backends.posgresql_psycopg2' isn't an ...
Coding example for the question 'django.db.backends.posgresql_psycopg2' isn't an available database backend-postgresql.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For all backends except sqlite you need to connect the database to use it.
You use fastapi so you should follow example in fastapi section of the ormar documentation. Basically you need to add connect and disconnect to fastapi instance events.
As described in https://github.com/collerek/ormar/blob/master/docs/fastapi.md#database-connection
Thanks a lot !