mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-06-29 09:20:01 +02:00
Bugfix/emit background error (#4156)
* print the test name when it runs * type hints * can't reuse session after an exception * better logging --------- Co-authored-by: Richard Kuo (Danswer) <rkuo@onyx.app>
This commit is contained in:
@ -11,10 +11,27 @@ def emit_background_error(
|
|||||||
"""Currently just saves a row in the background_errors table.
|
"""Currently just saves a row in the background_errors table.
|
||||||
|
|
||||||
In the future, could create notifications based on the severity."""
|
In the future, could create notifications based on the severity."""
|
||||||
with get_session_with_current_tenant() as db_session:
|
error_message = ""
|
||||||
|
|
||||||
|
# try to write to the db, but handle IntegrityError specifically
|
||||||
try:
|
try:
|
||||||
|
with get_session_with_current_tenant() as db_session:
|
||||||
create_background_error(db_session, message, cc_pair_id)
|
create_background_error(db_session, message, cc_pair_id)
|
||||||
except IntegrityError as e:
|
except IntegrityError as e:
|
||||||
# Log an error if the cc_pair_id was deleted or any other exception occurs
|
# Log an error if the cc_pair_id was deleted or any other exception occurs
|
||||||
error_message = f"Failed to create background error: {str(e)}. Original message: {message}"
|
error_message = (
|
||||||
|
f"Failed to create background error: {str(e)}. Original message: {message}"
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not error_message:
|
||||||
|
return
|
||||||
|
|
||||||
|
# if we get here from an IntegrityError, try to write the error message to the db
|
||||||
|
# we need a new session because the first session is now invalid
|
||||||
|
try:
|
||||||
|
with get_session_with_current_tenant() as db_session:
|
||||||
create_background_error(db_session, error_message, None)
|
create_background_error(db_session, error_message, None)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
@ -108,3 +108,13 @@ def admin_user() -> DATestUser:
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def reset_multitenant() -> None:
|
def reset_multitenant() -> None:
|
||||||
reset_all_multitenant()
|
reset_all_multitenant()
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_runtest_logstart(nodeid: str, location: tuple[str, int | None, str]) -> None:
|
||||||
|
print(f"\nTest start: {nodeid}")
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_runtest_logfinish(
|
||||||
|
nodeid: str, location: tuple[str, int | None, str]
|
||||||
|
) -> None:
|
||||||
|
print(f"\nTest end: {nodeid}")
|
||||||
|
Reference in New Issue
Block a user