-
-
Notifications
You must be signed in to change notification settings - Fork 275
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
Forward-compatible usage of Pydantic v1 #1950
Comments
aaronsteers
changed the title
Forwards-compatible usage of Python v1
Forward-compatible usage of Python v1
May 7, 2024
aaronsteers
changed the title
Forward-compatible usage of Python v1
Forward-compatible usage of Pydantic v1
May 7, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
I love that this codegen tool exists! We currently rely on models generated with this library, but we need to support compatibility with both Pydantic v1 and v2. I'm struggling with how to do this.
Describe the solution you'd like
I'd like
datamodel-code-generator
to be able to generate "v1" Pydantic models, but in a way that also forwards-compatible with Pydantic 2.This can be implemented with the following:
Describe alternatives you've considered
I tried using a modified version of the above and then specifying an override base class of
..BaseModel_v1
:Any way I try implement the base class override, however, I still end up with an extra (and incorrect) import statement of
BaseModel_v1
. I tried the base class ofBaseModel_v1
,.BaseModel_v1
, and..BaseModel_v1
.Ideally, for this workaround to work, an override base class without a
.
in it would be expected to have already been imported, since its impossible to import a class without a module reference and so rather thanimport BaseModel_v1
being generated if I set base class ofBaseModel_v1
, that scenario would just skip an attempt to import.The closest I could get was this invocation, using the above code in the header file:
Additional context
WIP PR in downstream library here:
The text was updated successfully, but these errors were encountered: