-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Fix Pydantic V2 RootModel inheritance #1477
Fix Pydantic V2 RootModel inheritance #1477
Conversation
In Pydantic V2, root models are defined by inheriting RootModel class and defining the root field.
for more information, see https://pre-commit.ci
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1477 +/- ##
===========================================
Coverage 100.00% 100.00%
===========================================
Files 11 32 +21
Lines 1020 3569 +2549
Branches 201 838 +637
===========================================
+ Hits 1020 3569 +2549
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
d4879b7
to
d85fafb
Compare
TypedDict is not available on pre-3.8, so changing this to Any to avoid issues...
Well, now all the tests are passing but the Codecov step is failing because the GitHub Actions tests run before code coverage was reported and a 404 error was raised from the test action. |
I have cleared CI chache and re-invoke actions. |
Thank you very much!! |
You're welcome! Thank you very much for this amazing tool! |
In Pydantic V2, root models are defined by inheriting
RootModel
class and defining theroot
field. However, in Pydantic V1, root models were defined by inheriting the sameBaseModel
and declaring a__root__
field.Developers can set the
base_class
parameter to override the inherited class in the generated models. For Pydantic V1, this works fine in all cases as both Normal Models and Root Models were inheriting the same class. But for Pydantic V2 Root Models need to inherit a different class, so having the samebase_class
for both Normal Models and Root Models no longer works (as Root Models will be detected as Normal Models with a literalroot
field).Considering how Enum's are being generated (by ignoring
base_class
), it seems like the best approach is the same one: for Pydantic V2 Root Models, ignore ifbase_class
is set and always inheritRootModel
. This PR applies this change for Pydantic V2 Root Models only.Fixes #1435 (kinda, see #1435 (comment))