mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
fix: prevent None values in auto-metadata from causing KeyError (#15842)
## Problem
When users configure auto-metadata for a dataset, parsing crashes with:
```
KeyError: 'properties' in gen_metadata → schema["properties"]
```
## Root Cause
Pydantic `AutoMetadataField` defaults `enum` and `description` to `None`
when the frontend omits these fields:
```python
class AutoMetadataField(Base):
enum: Annotated[list[str] | None, Field(default=None)]
description: Annotated[str | None, Field(default=None)]
```
These `None` values propagate through the call chain and cause two
crashes:
This commit is contained in:
@@ -399,11 +399,11 @@ def _is_metadata_list(obj: list) -> bool:
|
||||
key = item.get("key")
|
||||
if not isinstance(key, str) or not key:
|
||||
return False
|
||||
if "enum" in item and not isinstance(item["enum"], list):
|
||||
if "enum" in item and item["enum"] is not None and not isinstance(item["enum"], list):
|
||||
return False
|
||||
if "description" in item and not isinstance(item["description"], str):
|
||||
if "description" in item and item["description"] is not None and not isinstance(item["description"], str):
|
||||
return False
|
||||
if "descriptions" in item and not isinstance(item["descriptions"], str):
|
||||
if "descriptions" in item and item["descriptions"] is not None and not isinstance(item["descriptions"], str):
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -414,12 +414,12 @@ def turn2jsonschema(obj: dict | list) -> Dict[str, Any]:
|
||||
if isinstance(obj, list) and _is_metadata_list(obj):
|
||||
normalized = []
|
||||
for item in obj:
|
||||
description = item.get("description", item.get("descriptions", ""))
|
||||
description = item.get("description") or item.get("descriptions") or ""
|
||||
normalized_item = {
|
||||
"key": item.get("key"),
|
||||
"description": description,
|
||||
}
|
||||
if "enum" in item:
|
||||
if "enum" in item and item["enum"] is not None:
|
||||
normalized_item["enum"] = item["enum"]
|
||||
normalized.append(normalized_item)
|
||||
return metadata_schema(normalized)
|
||||
|
||||
Reference in New Issue
Block a user