fix: Never call simple_search from exception handler during context cleanup
This commit is contained in:
@@ -481,8 +481,7 @@ def hierarchical_search(
|
|||||||
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
# Check if this is our fallback signal
|
# Check if this is our fallback signal
|
||||||
error_msg = str(e)
|
if str(e) == "FALLBACK_TO_SIMPLE":
|
||||||
if error_msg == "FALLBACK_TO_SIMPLE" or error_msg.startswith("FALLBACK_ERROR:"):
|
|
||||||
# Fallback to simple search (outside context manager)
|
# Fallback to simple search (outside context manager)
|
||||||
results = simple_search(query, limit, author_filter, work_filter)
|
results = simple_search(query, limit, author_filter, work_filter)
|
||||||
return {
|
return {
|
||||||
@@ -497,19 +496,14 @@ def hierarchical_search(
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
# Fallback to simple search on error (unless forced)
|
# CRITICAL: Never call simple_search() here - we're still cleaning up the context manager!
|
||||||
if not force_hierarchical:
|
# Instead, return empty result and let the caller decide if they want to retry
|
||||||
# CRITICAL: We're still inside the 'with' block here!
|
|
||||||
# Signal fallback to exit context manager before calling simple_search()
|
|
||||||
raise ValueError(f"FALLBACK_ERROR: {str(e)}")
|
|
||||||
else:
|
|
||||||
# Forced hierarchical: return error in hierarchical format
|
|
||||||
return {
|
return {
|
||||||
"mode": "hierarchical",
|
"mode": "hierarchical" if force_hierarchical else "simple",
|
||||||
"sections": [],
|
"sections": [],
|
||||||
"results": [],
|
"results": [],
|
||||||
"total_chunks": 0,
|
"total_chunks": 0,
|
||||||
"fallback_reason": f"Erreur lors de la recherche hiérarchique: {str(e)}",
|
"fallback_reason": f"Erreur lors de la recherche: {str(e)}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user