Fixhancement: better handle empty fields from AI suggestions (#13454)

This commit is contained in:
shamoon
2026-07-31 08:19:22 -07:00
committed by GitHub
parent 30fe172847
commit 919ffdd794
2 changed files with 41 additions and 5 deletions
+6 -5
View File
@@ -1,12 +1,13 @@
from pydantic import BaseModel
from pydantic import Field
class DocumentClassifierSchema(BaseModel):
"""Schema for document classification suggestions."""
title: str
tags: list[str]
correspondents: list[str]
document_types: list[str]
storage_paths: list[str]
dates: list[str]
tags: list[str] = Field(default_factory=list)
correspondents: list[str] = Field(default_factory=list)
document_types: list[str] = Field(default_factory=list)
storage_paths: list[str] = Field(default_factory=list)
dates: list[str] = Field(default_factory=list)
+35
View File
@@ -0,0 +1,35 @@
import pytest
from pydantic import ValidationError
from paperless_ai.base_model import DocumentClassifierSchema
@pytest.mark.parametrize(
"omitted_field",
[
"tags",
"correspondents",
"document_types",
"storage_paths",
"dates",
],
)
def test_document_classifier_schema_defaults_omitted_list_field(omitted_field):
data = {
"title": "Test Title",
"tags": ["test"],
"correspondents": ["Test Correspondent"],
"document_types": ["Test Document Type"],
"storage_paths": ["Test Storage Path"],
"dates": ["2026-07-31"],
}
del data[omitted_field]
result = DocumentClassifierSchema(**data)
assert getattr(result, omitted_field) == []
def test_document_classifier_schema_requires_title():
with pytest.raises(ValidationError, match="title"):
DocumentClassifierSchema()