Skip to content

index of a batch of documents fails if even one document has empty content #307

@kyteinsky

Description

@kyteinsky

Which version of Nextcloud are you using?

v34.0.0

Which version of PHP context_chat are you using?

v5.4.0-beta0

Which version of backend context_chat are you using?

v5.4.0-beta0

Nextcloud deployment method?

docker-compose

Describe the Bug

the whole batch of files/content provider documents fails if there is even one of the items in the list that has empty content or fails the validation for any field.

validation of a single item where empty content fails:

class CommonSourceItem(BaseModel):
userIds: Annotated[list[str], AfterValidator(_validate_user_ids)]
# source_id of the form "appId__providerId: itemId"
reference: Annotated[str, AfterValidator(_validate_source_id)]
title: str
modified: int
type: str
provider: Annotated[str, AfterValidator(_validate_provider_id)]
size: float
@field_validator('modified', mode='before')
@classmethod
def validate_modified(cls, v):
if isinstance(v, int):
return v
if isinstance(v, str):
try:
return int(v)
except ValueError as e:
raise ValueError(f'Invalid modified value: {v}') from e
raise ValueError(f'Invalid modified type: {type(v)}')
@field_validator('reference', 'title', 'type', 'provider')
@classmethod
def validate_strings_non_empty(cls, v):
if not isinstance(v, str) or v.strip() == '':
raise ValueError('Must be a non-empty string')
return v.strip()
@field_validator('size')
@classmethod
def validate_size(cls, v):
if isinstance(v, int | float) and v >= 0:
return float(v)
raise ValueError(f'Invalid size value: {v}, must be a non-negative number')
@model_validator(mode='after')
def validate_type(self) -> Self:
if self.reference.startswith(FILES_PROVIDER_ID) and self.type not in SUPPORTED_MIMETYPES:
raise ValueError(f'Unsupported file type: {self.type} for reference {self.reference}')
return self

To Reproduce

/

PHP logs (Warning these might contain sensitive information)

No response

Ex-App logs (Warning these might contain sensitive information)

No response

Server logs (if applicable)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions