Hi Stefan,
When testing the csaf module with pydantic V2 we noticed the following:
on this line in our code:
from csaf.document import Tracking
we get an error:
AttributeError: 'FieldInfo' object has no attribute 'min_length'
We think this can be resolved by removing line #43 from csaf/document.py (https://git.sr.ht/~sthagen/csaf/tree/default/item/csaf/document.py#L43)
Jacco
Thank you for reporting the bug (implementation error).
The fix though should not be removing the constraint, but instead implement the correct one (https://docs.oasis-open.org/csaf/csaf/v2.0/os/csaf-v2.0-os.html#321121-document-property---tracking---aliases).
The
min_length
attribute in Pydantic is only valid for strings andaliases
is a list (JSON array) ofAlias
elements.So, I will add a validator "function" instead to the class. Something like:
class Tracking(BaseModel): # ... @classmethod @no_type_check @field_validator('aliases') def check_when_present_not_empty(cls, v): if not v: raise ValueError('optional element if present must not be empty') return v
Fixed with version 2023.11.27
Thanks!
Works for us.