mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-05-17 10:29:49 -05:00
fix(audit): reuse session connection when checking audit_logs table
Inspecting the engine directly opens a second connection, which under SQLite can contend with a write lock held by the current flush and cause spurious failures during tests. Bind the inspector to the session's existing connection when available and fall back to the engine otherwise.
This commit is contained in:
+7
-2
@@ -433,8 +433,13 @@ def check_audit_table_exists(force_check=False):
|
||||
return _audit_table_exists
|
||||
|
||||
try:
|
||||
# Try to check if the table exists
|
||||
inspector = sqlalchemy_inspect(db.engine)
|
||||
# Prefer the current session connection so SQLite tests do not open a
|
||||
# second connection while a flush is acquiring a write lock.
|
||||
try:
|
||||
bind = db.session.connection()
|
||||
except Exception:
|
||||
bind = db.engine
|
||||
inspector = sqlalchemy_inspect(bind)
|
||||
tables = inspector.get_table_names()
|
||||
exists = "audit_logs" in tables
|
||||
_audit_table_exists = exists
|
||||
|
||||
Reference in New Issue
Block a user