mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-31 16:15:58 +00:00
Fixhancement: better handle empty fields from AI suggestions (#13454)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user