datamodel-code-generator
datamodel-code-generator copied to clipboard
Fix Missing Imports
The processed_models array stores Processed objects, which include models and their imports after being handled by the parser/base.py:parse function. However, since models are objects (passed by reference), the Processed objects and their models can be modified after creation. This can sometimes result in model changes without corresponding updates to the model imports, leading to broken Pydantic models (example is given in #2001).
This PR addresses this issue by introducing a post-processing step in the base parser's parsing method, ensuring that all necessary imports are correctly included.
Fixes #2001
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 100.00%. Comparing base (
9ac0425) to head (9e7eafb).
Additional details and impacted files
@@ Coverage Diff @@
## main #2009 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 38 38
Lines 4188 4197 +9
Branches 961 967 +6
=========================================
+ Hits 4188 4197 +9
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 99.66% <100.00%> (+<0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
CodSpeed Performance Report
Merging #2009 will not alter performance
Comparing luca-knaack-webcom:feat/2001-missing-imports (9e7eafb) with main (9ac0425)
Summary
✅ 29 untouched benchmarks
@luca-knaack-webcom Thank you for creating the PR again. Could you please fix the test coverage?
https://github.com/koxudaxi/datamodel-code-generator/pull/2009/files
@koxudaxi
Just performed a final code-cleanup. Everything is now covered by tests. While there is one pragma: no cover, this is still covered by those lines being covered 😅