fix: resolve _sort_key error in Redis get_docs_paginated function

This commit is contained in:
yangdx 2025-07-31 02:16:56 +08:00
parent d0bc5e7c4a
commit 2af8a93dc7
2 changed files with 10 additions and 13 deletions

View file

@ -999,14 +999,14 @@ class RedisDocStatusStorage(DocStatusStorage):
if "error_msg" not in data: if "error_msg" not in data:
data["error_msg"] = None data["error_msg"] = None
# Add sort key for sorting # Calculate sort key for sorting (but don't add to data)
if sort_field == "id": if sort_field == "id":
data["_sort_key"] = doc_id sort_key = doc_id
else: else:
data["_sort_key"] = data.get(sort_field, "") sort_key = data.get(sort_field, "")
doc_status = DocProcessingStatus(**data) doc_status = DocProcessingStatus(**data)
all_docs.append((doc_id, doc_status)) all_docs.append((doc_id, doc_status, sort_key))
except (json.JSONDecodeError, KeyError) as e: except (json.JSONDecodeError, KeyError) as e:
logger.error( logger.error(
@ -1021,16 +1021,12 @@ class RedisDocStatusStorage(DocStatusStorage):
logger.error(f"Error getting paginated docs: {e}") logger.error(f"Error getting paginated docs: {e}")
return [], 0 return [], 0
# Sort documents # Sort documents using the separate sort key
reverse_sort = sort_direction.lower() == "desc" reverse_sort = sort_direction.lower() == "desc"
all_docs.sort( all_docs.sort(key=lambda x: x[2], reverse=reverse_sort)
key=lambda x: getattr(x[1], "_sort_key", ""), reverse=reverse_sort
)
# Remove sort key from documents # Remove sort key from tuples and keep only (doc_id, doc_status)
for doc_id, doc in all_docs: all_docs = [(doc_id, doc_status) for doc_id, doc_status, _ in all_docs]
if hasattr(doc, "_sort_key"):
delattr(doc, "_sort_key")
total_count = len(all_docs) total_count = len(all_docs)

View file

@ -145,7 +145,8 @@ class LightragPathFilter(logging.Filter):
# Filter out successful GET requests to filtered paths # Filter out successful GET requests to filtered paths
if ( if (
method == "GET" or method == "POST" method == "GET"
or method == "POST"
and (status == 200 or status == 304) and (status == 200 or status == 304)
and path in self.filtered_paths and path in self.filtered_paths
): ):