From 29d2e5adc22fcf2cb42b6f4e881e548c8ed7c9e3 Mon Sep 17 00:00:00 2001 From: Sergey Morozov Date: Fri, 29 Jan 2021 17:14:15 +0300 Subject: [PATCH] Fixed counter on failed connection --- databases/core.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/databases/core.py b/databases/core.py index 2bab6735..64117147 100644 --- a/databases/core.py +++ b/databases/core.py @@ -215,8 +215,12 @@ def __init__(self, backend: DatabaseBackend) -> None: async def __aenter__(self) -> "Connection": async with self._connection_lock: self._connection_counter += 1 - if self._connection_counter == 1: - await self._connection.acquire() + try: + if self._connection_counter == 1: + await self._connection.acquire() + except Exception as e: + self._connection_counter -= 1 + raise e return self async def __aexit__(