datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Fix Missing Imports

Open luca-knaack-webcom opened this issue 1 year ago • 3 comments

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

luca-knaack-webcom avatar Jun 18 '24 12:06 luca-knaack-webcom

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.

codecov[bot] avatar Jun 25 '24 14:06 codecov[bot]

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

codspeed-hq[bot] avatar Jun 26 '24 16:06 codspeed-hq[bot]

@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 avatar Jun 28 '24 16:06 koxudaxi

@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 😅

luca-knaack-webcom avatar Jul 01 '24 08:07 luca-knaack-webcom