Spaces:
Paused
Paused
Commit ·
39c2d11
1
Parent(s): c8cb83c
fix: prevent NameError when QU disabled and fix connection leak
Browse files- Add route="vector" and sql_query=None defaults before the
`if qu_enabled:` block in both app_cli.py and app_web.py,
preventing NameError when query understanding is disabled.
- Wrap sqlite3 connection in try/finally in sql_retriever.py
to ensure conn.close() runs even if execute/fetchmany raises.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- app_cli.py +2 -0
- app_web.py +2 -0
- src/sql_retriever.py +7 -6
app_cli.py
CHANGED
|
@@ -275,6 +275,8 @@ def main() -> None:
|
|
| 275 |
original_query = user_input
|
| 276 |
search_query = user_input
|
| 277 |
display_query = user_input
|
|
|
|
|
|
|
| 278 |
|
| 279 |
if qu_enabled:
|
| 280 |
with console.status("[bold blue]Understanding your question...[/bold blue]"):
|
|
|
|
| 275 |
original_query = user_input
|
| 276 |
search_query = user_input
|
| 277 |
display_query = user_input
|
| 278 |
+
route = "vector"
|
| 279 |
+
sql_query = None
|
| 280 |
|
| 281 |
if qu_enabled:
|
| 282 |
with console.status("[bold blue]Understanding your question...[/bold blue]"):
|
app_web.py
CHANGED
|
@@ -154,6 +154,8 @@ def render_chat():
|
|
| 154 |
|
| 155 |
search_query = combined
|
| 156 |
display_query = combined
|
|
|
|
|
|
|
| 157 |
max_clarifications = qu_cfg.get("max_clarifications", 1)
|
| 158 |
|
| 159 |
if qu_enabled:
|
|
|
|
| 154 |
|
| 155 |
search_query = combined
|
| 156 |
display_query = combined
|
| 157 |
+
route = "vector"
|
| 158 |
+
sql_query = None
|
| 159 |
max_clarifications = qu_cfg.get("max_clarifications", 1)
|
| 160 |
|
| 161 |
if qu_enabled:
|
src/sql_retriever.py
CHANGED
|
@@ -51,12 +51,13 @@ def execute_sql_query(sql_query: str, cfg: dict) -> list[dict]:
|
|
| 51 |
|
| 52 |
try:
|
| 53 |
conn = sqlite3.connect(f"file:{db_path}?mode=ro", uri=True)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
except Exception:
|
| 61 |
return []
|
| 62 |
|
|
|
|
| 51 |
|
| 52 |
try:
|
| 53 |
conn = sqlite3.connect(f"file:{db_path}?mode=ro", uri=True)
|
| 54 |
+
try:
|
| 55 |
+
conn.row_factory = sqlite3.Row
|
| 56 |
+
cursor = conn.execute(sql_query)
|
| 57 |
+
rows = cursor.fetchmany(max_rows)
|
| 58 |
+
return [dict(row) for row in rows]
|
| 59 |
+
finally:
|
| 60 |
+
conn.close()
|
| 61 |
except Exception:
|
| 62 |
return []
|
| 63 |
|