Skip to content

Script raises AttributeError using Pydantic 2.3 #41

Closed
@waterfallwhitebread

Description

@waterfallwhitebread

Using this script in my project with Pydantic 2.3 (likely all 2.x versions, just tried 2.2 also with same result) with example provided in readme leads to an AttributeError:

C:\SDKs\Python\xxx\Lib\site-packages\pydantic\_migration.py:276: UserWarning: `pydantic.generics:GenericModel` has been moved to `pydantic.BaseModel`.
  warnings.warn(f'`{import_path}` has been moved to `{new_location}`.')
2023-09-19 07:18:05,304 Finding pydantic models...
Traceback (most recent call last):
  File "C:\SDKs\Python\xxx\Lib\site-packages\pydantic2ts\cli\script.py", line 285, in <module>
    main()
  File "C:\SDKs\Python\xxx\Lib\site-packages\pydantic2ts\cli\script.py", line 276, in main
    return generate_typescript_defs(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\SDKs\Python\xxx\Lib\site-packages\pydantic2ts\cli\script.py", line 201, in generate_typescript_defs
    models = extract_pydantic_models(import_module(module))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\SDKs\Python\xxx\Lib\site-packages\pydantic2ts\cli\script.py", line 81, in extract_pydantic_models
    for _, model in inspect.getmembers(module, is_concrete_pydantic_model):
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\inspect.py", line 595, in getmembers
    return _getmembers(object, predicate, getattr)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\inspect.py", line 586, in _getmembers
    if not predicate or predicate(value):
                        ^^^^^^^^^^^^^^^^
  File "C:\SDKs\Python\xxx\Lib\site-packages\pydantic2ts\cli\script.py", line 69, in is_concrete_pydantic_model
    return bool(obj.__concrete__)
                ^^^^^^^^^^^^^^^^
  File "C:\SDKs\Python\xxx\Lib\site-packages\pydantic\_internal\_model_construction.py", line 210, in __getattr__
    raise AttributeError(item)
AttributeError: __concrete__

Using Pydantic 1.9 generated correct TS file.
Is this script only supposed to be working with Pydantic 1.x? I didn't see such a limitation in documentation.
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions