fix: deduplicate enum imports when merging grouped and individual imports #2945
+77
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Info
New Features
N/A
Bug Fixes
--expanded-formatOriginal Bug Analysis
When using
sea-orm-cli generate entitywith--expanded-formatandpreserve_user_modificationsenabled, duplicate enum imports were created if the old file had grouped imports and the new file generated individual imports.For example, if the old file had:
And the new file generated:
The merge would incorrectly produce all three import lines instead of just the two individual imports.
Root Cause
The merge logic used structural equality (
HashSet<ItemUse>) to deduplicate imports. This failed to recognize that grouped imports and individual imports for the same paths are semantically equivalent and should be deduplicated.Fix
normalize_use_paths()function to flatten use statements into canonical import pathsHashSet<ItemUse>toHashSet<String>for semantic path comparisonBreaking Changes
N/A — this fix maintains backward compatibility while improving merge behavior.
Changes
sea-orm-codegen/src/merge/mod.rs:duplicate_enum_imports_grouped_vs_individual