From e57d0f345e85be56cae5dbefb22faf659066d36a Mon Sep 17 00:00:00 2001 From: Eugenio Panadero Date: Tue, 17 Oct 2017 10:06:49 +0200 Subject: [PATCH] Recorder: Extra check to incoming connections which could be not sqlite3 ones (#9867) * Extra check to incoming connections The incoming connection could be other than self.db_url, because some 'custom_component' could be making these, and then, if they're not sqlite3 connections, an error will raise because those haven't the `dbapi_connection.isolation_level` attrib. * lint fix * simplify check: isinstance test only --- homeassistant/components/recorder/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/recorder/__init__.py b/homeassistant/components/recorder/__init__.py index 5959165779b..eb92f345a07 100644 --- a/homeassistant/components/recorder/__init__.py +++ b/homeassistant/components/recorder/__init__.py @@ -351,6 +351,7 @@ class Recorder(threading.Thread): from sqlalchemy.engine import Engine from sqlalchemy.orm import scoped_session from sqlalchemy.orm import sessionmaker + from sqlite3 import Connection from . import models @@ -360,7 +361,7 @@ class Recorder(threading.Thread): @event.listens_for(Engine, "connect") def set_sqlite_pragma(dbapi_connection, connection_record): """Set sqlite's WAL mode.""" - if self.db_url.startswith("sqlite://"): + if isinstance(dbapi_connection, Connection): old_isolation = dbapi_connection.isolation_level dbapi_connection.isolation_level = None cursor = dbapi_connection.cursor()