Consider this:
from pydantic import BaseModel
@registry.dim('v1')
class Dim(BaseModel):
length: int
@registry.architecture('v1')
def load_architecture(foo: str, dim: Dim):
...
config str = """
[model]
@architecture = 'v1'
length = 6
[model.dim]
@dim = 'v1'
length = 6
"""
So the problem with this is that thinc.Config will generate an ArgumentModel from the registered architecture function
https://github.com/explosion/thinc/blob/adeb99ab7f005228c5a45a8c755929a6bb081d78/thinc/config.py#L910
in config._fill
validation.update(result.dict(exclude=exclude_validation))
filled, final = cls._update_from_parsed(validation, filled, final) # <- this breaks
in the first line both validation and results both have the dim attribute at the desired pydantic class.
however on the call to results.dict() the pydantic model is transformed to a dictionary as is the behavior of Pydantic .dict method. Then in _update_from_parsed()
https://github.com/explosion/thinc/blob/adeb99ab7f005228c5a45a8c755929a6bb081d78/thinc/config.py#L932
if isinstance(value, dict):
filled[key], final[key] = cls._update_from_parsed(
value, filled[key], final[key]
)
It iterates over validation items, thinks that dim is a dict and tries to set the key on the pydantic model in final[key].
I think there needs to be some way for Config to tell apart configs that come with a pydantic Schema and those that come from functions that happen to contain pydantic models. (Luckily I also have attrs in this project so could avoid erroneously casting it to a dict after figuring out the problem)
Consider this:
So the problem with this is that thinc.Config will generate an
ArgumentModelfrom the registered architecture functionhttps://github.com/explosion/thinc/blob/adeb99ab7f005228c5a45a8c755929a6bb081d78/thinc/config.py#L910
in
config._fillin the first line both validation and results both have the dim attribute at the desired pydantic class.
however on the call to
results.dict()the pydantic model is transformed to a dictionary as is the behavior of Pydantic .dict method. Then in_update_from_parsed()https://github.com/explosion/thinc/blob/adeb99ab7f005228c5a45a8c755929a6bb081d78/thinc/config.py#L932
It iterates over
validationitems, thinks thatdimis a dict and tries to set the key on the pydantic model infinal[key].I think there needs to be some way for Config to tell apart configs that come with a pydantic Schema and those that come from functions that happen to contain pydantic models. (Luckily I also have
attrsin this project so could avoid erroneously casting it to a dict after figuring out the problem)