Skip to content

Commit ed4a23d

Browse files
authored
Override connect method in RecorderPool (home-assistant#148490)
1 parent 0729b3a commit ed4a23d

File tree

1 file changed

+7
-0
lines changed
  • homeassistant/components/recorder

1 file changed

+7
-0
lines changed

homeassistant/components/recorder/pool.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from sqlalchemy.pool import (
1313
ConnectionPoolEntry,
1414
NullPool,
15+
PoolProxiedConnection,
1516
SingletonThreadPool,
1617
StaticPool,
1718
)
@@ -119,6 +120,12 @@ def _do_get_db_connection_protected(self) -> ConnectionPoolEntry:
119120
)
120121
return NullPool._create_connection(self) # noqa: SLF001
121122

123+
def connect(self) -> PoolProxiedConnection:
124+
"""Return a connection from the pool."""
125+
if threading.get_ident() in self.recorder_and_worker_thread_ids:
126+
return super().connect()
127+
return NullPool.connect(self)
128+
122129

123130
class MutexPool(StaticPool):
124131
"""A pool which prevents concurrent accesses from multiple threads.

0 commit comments

Comments
 (0)