Skip to content

Dedupe custom field definitions on re-import#75

Merged
SiteRelEnby merged 2 commits into
mainfrom
fix-import-duplicate-custom-fields
May 25, 2026
Merged

Dedupe custom field definitions on re-import#75
SiteRelEnby merged 2 commits into
mainfrom
fix-import-duplicate-custom-fields

Conversation

@SiteRelEnby
Copy link
Copy Markdown
Contributor

Summary

Restoring a Sheaf export into a system that already had its custom fields stacked a second copy of every definition ("Pronouns", "Pronouns", ...), because the importer created definitions unconditionally. This dedupes them. Follow-up to the import-completeness work merged in #74; sequenced as unreleased (not folded into v0.2.2).

Change

  • Custom field definitions are deduped by (name, type) against the target system and within the file itself, reusing the existing definition rather than minting a twin. The system's own config (privacy / order / options) on a reused field is left untouched.
  • Members are still added rather than merged (member dedup is separate, larger work), so their values attach to the fresh member rows under the shared definition.
  • Field-value inserts guard (field_id, member_id) uniqueness in-run, so a reused definition (a file with duplicate defs, or future deduped members) can't trip the UNIQUE(field_id, member_id) constraint mid-import.

Also

  • Syncs uv.lock to 0.2.2 (the v0.2.2 bump updated pyproject but not the lockfile; only the version field moves, no dependency resolutions change). Same lockfile-drift class as the package-lock.json fix in v0.2.2.

Tests

  • New runner test: importing the same export twice creates the field once, the second run reports zero new fields, and exactly one definition survives.
  • 11 passed across the import runner + preview suite; ruff clean.

Not in scope

Member deduplication (re-import stays additive for members).

Restoring a Sheaf export into a system that already had its custom
fields stacked a second copy of every definition, since the importer
created them unconditionally. Dedupe by (name, type) against the target
system and within the file itself, reusing the existing definition
rather than minting a twin. Members aren't deduped, so their values
still attach to the fresh member rows under the shared definition.

Field-value inserts now guard (field_id, member_id) uniqueness in-run so
a reused definition (a file with duplicate defs, or future deduped
members) can't trip the UNIQUE constraint mid-import.

Left as additive follow-up work: member deduplication.
The v0.2.2 bump updated pyproject but not uv.lock, so the lockfile's
sheaf package version drifted. Only the version field changes; no
dependency resolutions move.
@SiteRelEnby SiteRelEnby merged commit e1b6ba0 into main May 25, 2026
4 checks passed
@SiteRelEnby SiteRelEnby deleted the fix-import-duplicate-custom-fields branch May 25, 2026 15:13
@SiteRelEnby SiteRelEnby mentioned this pull request May 26, 2026
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.

1 participant