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

msgspec: Mandatory attributes follow optional ones #1919

Open
maringuu opened this issue Apr 15, 2024 · 0 comments · May be fixed by #1942
Open

msgspec: Mandatory attributes follow optional ones #1919

maringuu opened this issue Apr 15, 2024 · 0 comments · May be fixed by #1942

Comments

@maringuu
Copy link

maringuu commented Apr 15, 2024

Steps to reproduce

  1. Download the NVD CVE schema
  2. Generate a msgpsec model:
datamodel-codegen \
    --input $schema_json \
    --input-file-type jsonschema \
    --output-model-type 'msgspec.Struct' \
    --snake-case-field \
    --output "."
  1. (Ignore the circular imports Importing generated code results in a circular dependency #836)
  2. Look at the class CveItem (and most other classes as well). It cannot be imported because a mandatory attribute follows an optional one, which is invalid in the generated __init__.

Expected behavior

Assuming #836 is fixed, the model should import correctly.

Workaround

Use kw_only=True

Setup

$ datamodel-codegen --version
0.25.5

$ python --version
Python 3.11.8
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

Successfully merging a pull request may close this issue.

1 participant