Fix multithreading issues for older SQLite versions (#1442)

* Update sql.py

* Parametrize check_same_thread

Co-authored-by: Malte Pietsch <malte.pietsch@deepset.ai>
This commit is contained in:
Adithya U R 2021-10-07 10:13:53 +02:00 committed by GitHub
parent 74d052277d
commit bff90c19d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,7 +74,8 @@ class SQLDocumentStore(BaseDocumentStore):
url: str = "sqlite://", url: str = "sqlite://",
index: str = "document", index: str = "document",
label_index: str = "label", 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. 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. 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 fail: an error is raised if the document ID of the document being added already
exists. 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 # save init parameters to enable export of component config as YAML
self.set_config( 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) ORMBase.metadata.create_all(engine)
Session = sessionmaker(bind=engine) Session = sessionmaker(bind=engine)
self.session = Session() self.session = Session()