mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Black
This commit is contained in:
@@ -18,7 +18,7 @@ def session_scope(*, hass=None, session=None):
|
||||
session = hass.data[DATA_INSTANCE].get_session()
|
||||
|
||||
if session is None:
|
||||
raise RuntimeError('Session required')
|
||||
raise RuntimeError("Session required")
|
||||
|
||||
need_rollback = False
|
||||
try:
|
||||
@@ -38,6 +38,7 @@ def session_scope(*, hass=None, session=None):
|
||||
def commit(session, work):
|
||||
"""Commit & retry work: Either a model or in a function."""
|
||||
import sqlalchemy.exc
|
||||
|
||||
for _ in range(0, RETRIES):
|
||||
try:
|
||||
if callable(work):
|
||||
@@ -64,15 +65,16 @@ def execute(qry):
|
||||
try:
|
||||
timer_start = time.perf_counter()
|
||||
result = [
|
||||
row for row in
|
||||
(row.to_native() for row in qry)
|
||||
if row is not None]
|
||||
row for row in (row.to_native() for row in qry) if row is not None
|
||||
]
|
||||
|
||||
if _LOGGER.isEnabledFor(logging.DEBUG):
|
||||
elapsed = time.perf_counter() - timer_start
|
||||
_LOGGER.debug('converting %d rows to native objects took %fs',
|
||||
len(result),
|
||||
elapsed)
|
||||
_LOGGER.debug(
|
||||
"converting %d rows to native objects took %fs",
|
||||
len(result),
|
||||
elapsed,
|
||||
)
|
||||
|
||||
return result
|
||||
except SQLAlchemyError as err:
|
||||
|
||||
Reference in New Issue
Block a user