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
pull/9920/head
Eugenio Panadero 2017-10-17 10:06:49 +02:00 committed by Pascal Vizeli
parent ed70fc9322
commit e57d0f345e
1 changed files with 2 additions and 1 deletions

View File

@ -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()