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:
Jack
2026-06-09 19:10:48 +08:00
committed by GitHub
parent 2773208159
commit 3eff41361b
4 changed files with 87 additions and 21 deletions

View File

@@ -955,6 +955,11 @@ async def relevant_chunks_with_toc(query: str, toc: list[dict], chat_mdl, topn:
META_DATA = load_prompt("meta_data")
async def gen_metadata(chat_mdl, schema: dict, content: str):
if not schema:
return ""
if "properties" not in schema:
logging.warning("gen_metadata: schema has no 'properties' key: %s", schema)
return ""
template = PROMPT_JINJA_ENV.from_string(META_DATA)
for k, desc in schema["properties"].items():
if "enum" in desc and not desc.get("enum"):