mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-10-10 21:26:01 +02:00
always finalize the serialized transaction so that it doesn't leak ou… (#2843)
* always finalize the serialized transaction so that it doesn't leak outside the function * re-raise the exception and log it
This commit is contained in:
@@ -387,6 +387,7 @@ def _prepare_index_attempt(
|
|||||||
# after the next commit:
|
# after the next commit:
|
||||||
# https://docs.sqlalchemy.org/en/20/orm/session_transaction.html#setting-isolation-for-individual-transactions
|
# https://docs.sqlalchemy.org/en/20/orm/session_transaction.html#setting-isolation-for-individual-transactions
|
||||||
db_session.connection(execution_options={"isolation_level": "SERIALIZABLE"}) # type: ignore
|
db_session.connection(execution_options={"isolation_level": "SERIALIZABLE"}) # type: ignore
|
||||||
|
try:
|
||||||
if tenant_id is not None:
|
if tenant_id is not None:
|
||||||
# Explicitly set the search path for the given tenant
|
# Explicitly set the search path for the given tenant
|
||||||
db_session.execute(text(f'SET search_path TO "{tenant_id}"'))
|
db_session.execute(text(f'SET search_path TO "{tenant_id}"'))
|
||||||
@@ -401,7 +402,9 @@ def _prepare_index_attempt(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if attempt is None:
|
if attempt is None:
|
||||||
raise RuntimeError(f"Unable to find IndexAttempt for ID '{index_attempt_id}'")
|
raise RuntimeError(
|
||||||
|
f"Unable to find IndexAttempt for ID '{index_attempt_id}'"
|
||||||
|
)
|
||||||
|
|
||||||
if attempt.status != IndexingStatus.NOT_STARTED:
|
if attempt.status != IndexingStatus.NOT_STARTED:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
@@ -409,9 +412,15 @@ def _prepare_index_attempt(
|
|||||||
f"Current status is '{attempt.status}'."
|
f"Current status is '{attempt.status}'."
|
||||||
)
|
)
|
||||||
|
|
||||||
# only commit once, to make sure this all happens in a single transaction
|
|
||||||
mark_attempt_in_progress(attempt, db_session)
|
mark_attempt_in_progress(attempt, db_session)
|
||||||
|
|
||||||
|
# only commit once, to make sure this all happens in a single transaction
|
||||||
|
db_session.commit()
|
||||||
|
except Exception:
|
||||||
|
db_session.rollback()
|
||||||
|
logger.exception("_prepare_index_attempt exceptioned.")
|
||||||
|
raise
|
||||||
|
|
||||||
return attempt
|
return attempt
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user