mirror of
https://github.com/explosion/spaCy.git
synced 2025-02-28 09:30:38 +03:00
Fix TokenPatternSchema pattern field validation
Empty pattern field should be considered invalid This is fixed by replacing minItems with min_items as described in Pydantic docs: https://pydantic-docs.helpmanual.io/usage/schema/
This commit is contained in:
parent
ed1c37189a
commit
1ad2213349
|
@ -257,7 +257,7 @@ class TokenPattern(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class TokenPatternSchema(BaseModel):
|
class TokenPatternSchema(BaseModel):
|
||||||
pattern: List[TokenPattern] = Field(..., minItems=1)
|
pattern: List[TokenPattern] = Field(..., min_items=1)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
extra = "forbid"
|
extra = "forbid"
|
||||||
|
|
14
spacy/tests/regression/test_issue6258.py
Normal file
14
spacy/tests/regression/test_issue6258.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import pydantic
|
||||||
|
import pytest
|
||||||
|
from pydantic import ValidationError
|
||||||
|
from spacy.schemas import TokenPattern, TokenPatternSchema
|
||||||
|
|
||||||
|
|
||||||
|
def test_issue6258():
|
||||||
|
"""Test that the non-empty constraint pattern field is respected"""
|
||||||
|
# These one is valid
|
||||||
|
TokenPatternSchema(pattern=[TokenPattern()])
|
||||||
|
# But an empty pattern list should fail to validate
|
||||||
|
# based on the schema's constraint
|
||||||
|
with pytest.raises(ValidationError):
|
||||||
|
TokenPatternSchema(pattern=[])
|
Loading…
Reference in New Issue
Block a user