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

main: fix configuration model validation after CLI args merge #1448

Merged
merged 9 commits into from
Aug 9, 2023

Conversation

airwoodix
Copy link
Contributor

@airwoodix airwoodix commented Jul 24, 2023

The bug reported in #1435 seems to originate in the Config._validate_base_class method: in Pydantic v2, @model_validator(mode="after") decorates an instance method instead of a class method that receives the raw values (the case for mode="before"). Therefore, except when called to alter set_args in Config.merge_args, the values argument is of type Config and "base_class" not in values is always true.

This MR is an attempt at fixing the issue, for Pydantic v2 only for the moment.

TODOS:

Closes #1435.

Signed-off-by: Etienne Wodey <etienne.wodey@aqt.eu>
@koxudaxi
Copy link
Owner

koxudaxi commented Aug 2, 2023

@model_validator(mode="after") decorates an instance method instead of a class method that receives the raw values (the case for mode="before").

@airwoodix
Thank you for creating this PR.
I didn't know the changes.

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (e9b6edf) 100.00% compared to head (71690da) 100.00%.
Report is 690 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##            master     #1448     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files           11        32     +21     
  Lines         1020      3563   +2543     
  Branches       201       838    +637     
===========================================
+ Hits          1020      3563   +2543     
Flag Coverage Δ
unittests 99.60% <99.54%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
datamodel_code_generator/__init__.py 100.00% <100.00%> (ø)
datamodel_code_generator/__main__.py 100.00% <100.00%> (ø)
datamodel_code_generator/format.py 100.00% <100.00%> (ø)
datamodel_code_generator/http.py 100.00% <100.00%> (ø)
datamodel_code_generator/imports.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/__init__.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/base.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/dataclass.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/enum.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/imports.py 100.00% <100.00%> (ø)
... and 22 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@koxudaxi koxudaxi marked this pull request as ready for review August 9, 2023 07:41
@koxudaxi koxudaxi merged commit 219e9d9 into koxudaxi:master Aug 9, 2023
73 checks passed
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 this pull request may close these issues.

Wrong parent class for pydantic V2 root models
2 participants