Repository navigation
Report key conflicts clearly when Umbraco won't change a key - #1276
Merged
Merged
Conversation
From Umbraco 18 the key of a saved entity can't change, so when the import matches an item by name and the keys differ it fails with "Cannot change the Key of an existing Content". All serializer key setters now go through SyncKeyHelper.SetKey, which turns that into a uSyncKeyConflictException naming the item, both keys and a docs link. The report also warns about the conflict ahead of time, using a probe that detects whether this Umbraco version blocks key changes, so the same code runs unchanged on v17 (where the set still works). Adds docs/key-mapping.md, the design for the KeyConflict: Map follow-up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 21, 2026
This was referenced Nov 23, 2026
Merged
This was referenced Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
From Umbraco 18 the key of a saved entity can't change (umbraco/Umbraco-CMS#21131). When an import matches an existing item by name and its key differs from the file, uSync tries to set the key and the import fails with a bare "Cannot change the Key of an existing Content". This PR doesn't fix the conflict. It replaces that message with one that says what happened and links to docs. It's step 1 of the plan in
docs/key-mapping.md.What changed
SyncKeyHelper.SetKey: every key setter in the serializers now goes through this one helper. That covers content/media/members, doctypes, property types, tabs, data types, dictionary items (only withForceKeySync), relation types, webhooks and containers. When Umbraco refuses the change on a saved item, the helper throwsuSyncKeyConflictException. The exception names the item, the site's key and the file's key, and links touSyncConstants.KeyConflictDocsUrl. The handler's existing error handling shows that message in the dashboard and the logs. Templates are untouched because file-based entities can still change their key.CanChangeKeyis protected, soSyncKeyHelper.KeysAreImmutabletries a key change on a throwawayEntityBaseonce and caches the result. The same code is correct on v17, where the set works, and on v18+, where it throws, with no version checks.OnKeyChange(URL cache cleanup) now runs after the key is set, so it can't clear the old key's URLs when the set fails. The check before it usesHasIdentity, as v18 does, so the forward-port merges cleanly.docs/key-mapping.md: design for the opt-inKeyConflict: Mapfollow-up. Nothing in this PR depends on it.Reviewer notes
https://docs.jumoo.co.uk/usync/uSync/reference/key-conflictsdoesn't exist yet.SyncKeyHelperTests(6 tests, written to pass on either version). The full suite passes on v17 (317). With the commits applied to v18/main the full suite also passes (391), and a separate check confirmedKeysAreImmutableis true there.🤖 Generated with Claude Code