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

Added protect namespace to Pydantic v2 ConfigDict #1489

Merged
merged 2 commits into from
Aug 16, 2023

Conversation

willarmiros
Copy link
Contributor

In Pydantic v2, a new "feature" was introduced that warned you if your field keys began with model_. However we have several fields that need to be named as such. So per Pydantic docs, this warning can be removed by setting protected_namespaces = () to remove the default protected namespace model_.

This PR allows an extra_data_template JSON file such as the following to be passed into the datamodel-codgen tool and have the protected_namespace change actually take affect. I verified that the warnings disappear on my project after this change.

{
    "MyModelThatIsCausingWarnings": {
        "config": {
            "protected_namespaces": []
        }
    }
}

@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (e9b6edf) 100.00% compared to head (60a5ddf) 100.00%.
Report is 696 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##            master     #1489     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files           11        32     +21     
  Lines         1020      3582   +2562     
  Branches       201       839    +638     
===========================================
+ Hits          1020      3582   +2562     
Flag Coverage Δ
unittests 99.63% <99.58%> (?)

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.

@willarmiros
Copy link
Contributor Author

It seems there's a missing test line and some typing issues with older Python versions, will try to resolve.

@willarmiros
Copy link
Contributor Author

@koxudaxi any chance of having this merged?

@koxudaxi koxudaxi merged commit 5aa9dc6 into koxudaxi:master Aug 16, 2023
73 checks passed
@willarmiros willarmiros deleted the protected-namespace branch August 16, 2023 18:08
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.

None yet

2 participants