# main.py
from pydantic import BaseModel
class Foo(BaseModel):
bar: str
class Config:
frozen = True
>> pydantic2ts --module main.py
[traceback omitted]
File \lib\site-packages\pydantic2ts\cli\script.py", line 145, in <listcomp>
model_extras = [m.Config.extra for m in models]
AttributeError: type object 'Config' has no attribute 'extra'
It appears that when you set Config options on a Pydantic model, the default options are not being added to the model's Config class. (I'm not exactly sure why--Pydantic has a bunch of metaclass razzmatazz that seems like it should populate subclass Configs, but it doesn't seem to be happening?) As a result, if you set some options, but don't set frozen, then the script throws an error when it tries to look up the frozen value. I think the fix is as easy as replacing all m.Config.extra with getattr(m.Config, 'extra', Extra.ignore), and doing that worked for my case, but I didn't do enough homework to feel confident that this wouldn't break something else.
Minimal example:
It appears that when you set
Config
options on a Pydantic model, the default options are not being added to the model'sConfig
class. (I'm not exactly sure why--Pydantic has a bunch of metaclass razzmatazz that seems like it should populate subclassConfig
s, but it doesn't seem to be happening?) As a result, if you set some options, but don't set frozen, then the script throws an error when it tries to look up the frozen value. I think the fix is as easy as replacing allm.Config.extra
withgetattr(m.Config, 'extra', Extra.ignore)
, and doing that worked for my case, but I didn't do enough homework to feel confident that this wouldn't break something else.