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

Combination of '--collapse-root-models and --field-constraints` errors out #2279

Open
ostefano opened this issue Jan 23, 2025 · 0 comments
Open

Comments

@ostefano
Copy link

ostefano commented Jan 23, 2025

Describe the bug
Combination of --collapse-root-models and --field-constraints errors out:

File "/path/.venv/lib/python3.13/site-packages/datamodel_code_generator/__main__.py", line 494, in main
    generate(
    ~~~~~~~~^
        input_=config.url or config.input or sys.stdin.read(),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<67 lines>...
        no_alias=config.no_alias,
        ^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/path/.venv/lib/python3.13/site-packages/datamodel_code_generator/__init__.py", line 507, in generate
    results = parser.parse()
  File "/path/.venv/lib/python3.13/site-packages/datamodel_code_generator/parser/base.py", line 1415, in parse
    self.__collapse_root_models(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        models, unused_models, imports, scoped_model_resolver
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/path/.venv/lib/python3.13/site-packages/datamodel_code_generator/parser/base.py", line 1058, in __collapse_root_models
    model_field.constraints = ConstraintsBase.merge_constraints(
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        root_type_field.constraints, model_field.constraints
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/path/.venv/lib/python3.13/site-packages/datamodel_code_generator/model/base.py", line 90, in merge_constraints
    if not issubclass(constraints_class, ConstraintsBase):  # pragma: no cover
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen abc>", line 123, in __subclasscheck__
TypeError: issubclass() arg 1 must be a class

To Reproduce

Schema https://csrc.nist.gov/schema/nvd/api/2.0/cve_api_json_2.0.schema

Used commandline:

$ datamodel-codegen --input ./schemas/cve-nvd/cve_api_json_2.0.schema.json --input-file-type jsonschema --output ~/Desktop/temp/ --output-model-type pydantic_v2.BaseModel --field-constraints --collapse-root-models

Expected behavior
Not an error

Version:

  • OS: OSX
  • Python version: 3.13
  • datamodel-code-generator version: 0.25.6
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

1 participant