From bff90c19d5f20e4cbcd3c50b198baff03b58d6e6 Mon Sep 17 00:00:00 2001 From: Adithya U R Date: Thu, 7 Oct 2021 10:13:53 +0200 Subject: [PATCH] Fix multithreading issues for older SQLite versions (#1442) * Update sql.py * Parametrize check_same_thread Co-authored-by: Malte Pietsch --- haystack/document_store/sql.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/haystack/document_store/sql.py b/haystack/document_store/sql.py index 62243ffb3..7878b92ae 100644 --- a/haystack/document_store/sql.py +++ b/haystack/document_store/sql.py @@ -74,7 +74,8 @@ class SQLDocumentStore(BaseDocumentStore): url: str = "sqlite://", index: str = "document", label_index: str = "label", - duplicate_documents: str = "overwrite" + duplicate_documents: str = "overwrite", + check_same_thread: bool = False ): """ An SQL backed DocumentStore. Currently supports SQLite, PostgreSQL and MySQL backends. @@ -89,14 +90,15 @@ class SQLDocumentStore(BaseDocumentStore): overwrite: Update any existing documents with the same ID when adding documents. fail: an error is raised if the document ID of the document being added already exists. + :param check_same_thread: Set to False to mitigate multithreading issues in older SQLite versions (see https://docs.sqlalchemy.org/en/14/dialects/sqlite.html?highlight=check_same_thread#threading-pooling-behavior) """ # save init parameters to enable export of component config as YAML self.set_config( - url=url, index=index, label_index=label_index, duplicate_documents=duplicate_documents + url=url, index=index, label_index=label_index, duplicate_documents=duplicate_documents, check_same_thread=check_same_thread ) - engine = create_engine(url) + engine = create_engine(url,connect_args={'check_same_thread': check_same_thread}) ORMBase.metadata.create_all(engine) Session = sessionmaker(bind=engine) self.session = Session()