Skip to content

Pipeline component ConfigValidationError regression in 3.8.13 #13944

@sentiasm

Description

@sentiasm

How to reproduce the behaviour

I got a component that worked on 3.8.11 but raised ConfigValidationError now

from pathlib import Path

import spacy
from spacy.lang.en import English
from spacy.language import Language
from spacy.tokens import Doc
from thinc.api import Config
 
 
class MyComponent:
    def __init__(self, nlp, name, path_: Path, set_: set[str]) -> None:
        self.path_= path_
        self.set_ = set_
 
    def __call__(self, doc: Doc) -> Doc:
        ...
 
@Language.factory(
    "my_component",
    default_config={"path_": "./model", "set_": set(["a", "b"])},
)
def create_path_component(nlp, name, path_: Path, set_: set[str]) -> MyComponent:
    return MyComponent(nlp=nlp, name=name, path_=path_, set_=set_)

CONFIG = """
[nlp]
lang = "en"
pipeline = ["my_component"]
 
[components]

[components.my_component]
factory = "my_component"
path_ = "./model
set_ = ["a", "b"]
"""

cfg = Config().from_str(CONFIG)
nlp = English.from_config(cfg)

component = nlp.get_pipe("my_component")
print("component.path_ is Path:", isinstance(component.path_, Path))
print("component.set_ is set:", isinstance(component.set_, set))

3.8.11 this worked OK, but now I got

---------------------------------------------------------------------------
ConfigValidationError                     Traceback (most recent call last)
[/tmp/ipykernel_21433/1043605428.py](https://localhost:8080/#) in <cell line: 0>()
     37 
     38 cfg = Config().from_str(CONFIG)
---> 39 nlp = English.from_config(cfg)
     40 
     41 component = nlp.get_pipe("my_component")

8 frames
[/usr/local/lib/python3.12/dist-packages/confection/_registry.py](https://localhost:8080/#) in _validate_promise_args(filled, schema, func_name, parent)
    343             )
    344     if errors:
--> 345         raise ConfigValidationError(
    346             config=filled,
    347             errors=errors,

ConfigValidationError: 

Config error for 'my_component'
my_component -> set_	at root: ['a', 'b'] is not set[str]
{'nlp': <spacy.lang.en.English object at 0x7d659676e1b0>, 'name': 'my_component', 'path_': '"./model', 'set_': ['a', 'b'], '@factories': 'my_component'}

Your Environment

  • spaCy version: 3.8.13
  • Platform: Linux-6.6.113+-x86_64-with-glibc2.35
  • Python version: 3.12.13
  • Pipelines: en_core_web_sm (3.8.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions