Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script raises AttributeError using Pydantic 2.3 #41

Open
waterfallwhitebread opened this issue Sep 19, 2023 · 1 comment
Open

Script raises AttributeError using Pydantic 2.3 #41

waterfallwhitebread opened this issue Sep 19, 2023 · 1 comment

Comments

@waterfallwhitebread
Copy link

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!

@nick-somebody
Copy link

There are fixes raised in PRs:

Personally I think this library should be following the versioning strategy of pydantic itself and documented as supporting matching major versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants