Skip to content

Deduplicate grouped vs individual imports on entity merge (#2947) - #3163

Merged
tyt2y3 merged 1 commit into
masterfrom
fix-2947-dedup-enum-imports
Aug 8, 2026
Merged

Deduplicate grouped vs individual imports on entity merge (#2947)#3163
tyt2y3 merged 1 commit into
masterfrom
fix-2947-dedup-enum-imports

Conversation

@tyt2y3

@tyt2y3 tyt2y3 commented Aug 8, 2026

Copy link
Copy Markdown
Member

Closes #2947.

Bug

When regenerating entities with --preserve-user-modifications, the merge deduplicated whole use statements by structural equality (HashSet<ItemUse>). If the user had grouped an enum import in the existing file while the freshly generated output uses individual imports, the two were not recognised as equivalent, so both were emitted:

use super::sea_orm_active_enums::{Status, Category};  // preserved from old file
use super::sea_orm_active_enums::Status;              // freshly generated
use super::sea_orm_active_enums::Category;            // freshly generated

Fix

Deduplicate at the individual import-leaf level. Each use tree is flattened into canonical leaf paths (super::foo::Bar, crate::Baz as Qux, sea_orm::entity::prelude::*), and a statement is dropped only when all of its leaves have already been imported. Grouped and individual imports of the same items now collapse to the same set of leaves and deduplicate against each other.

Non-overlapping grouped imports are still preserved verbatim (guarded by the existing complex_use test).

Tests

  • Added duplicate_enum_imports_grouped_vs_individual, which reproduces the report and fails against the old structural dedup.
  • All existing merge:: and codegen tests pass.

No changelog entry added — leaving the next-version slotting to the release workflow.

When regenerating entities with --preserve-user-modifications, the merge
deduplicated whole use statements by structural equality. A user-grouped
import (use foo::{A, B}) was therefore not recognised as equivalent to the
freshly generated individual imports (use foo::A; use foo::B;), so both were
emitted, producing duplicate imports.

Dedup at the individual import-leaf level instead: flatten each use tree into
canonical leaf paths and drop a statement only when all of its leaves have
already been imported. Non-overlapping grouped imports are still preserved
verbatim (covered by the existing complex_use test).
@tyt2y3
tyt2y3 force-pushed the fix-2947-dedup-enum-imports branch from e37d646 to 900a777 Compare August 8, 2026 16:49
@tyt2y3
tyt2y3 merged commit 90f4da0 into master Aug 8, 2026
39 checks passed
@tyt2y3
tyt2y3 deleted the fix-2947-dedup-enum-imports branch August 8, 2026 17:10
@github-actions

Copy link
Copy Markdown

🎉 Released In 2.0.2 🎉

Huge thanks for the contribution!
This feature has now been released, so it's a great time to upgrade.
Show some love with a ⭐ on our repo, every star counts!

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.

Enum imports duplicated when merging grouped and individual use statements

1 participant