Add cleanup in DocumentUrl tables when the content key changes.#869
Merged
Add cleanup in DocumentUrl tables when the content key changes.#869
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a foreign key constraint violation that occurs when a content item's Key changes during import. The fix involves cleaning up entries in the umbracoDocumentUrl table before the key change is applied, preventing the constraint violation. Umbraco will repopulate the table with the new Key on save.
Key Changes:
- Introduced
ISyncDocumentUrlCleanerinterface andSyncDocumentUrlCleanerimplementation to handle DocumentUrl table cleanup - Added
OnKeyChangevirtual method inContentSerializerBaseto allow subclasses to respond to key changes - Integrated URL cleaning into
ContentSerializerwhen key changes are detected
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| uSync.Core/Documents/ISyncDocumentUrlCleaner.cs | New interface for document URL cleanup functionality |
| uSync.Core/Documents/SyncDocumentUrlCleaner.cs | Implementation that deletes DocumentUrl entries by document key using repository |
| uSync.Core/uSyncCoreBuilderExtensions.cs | Registers the URL cleaner as a singleton service |
| uSync.Core/Serialization/Serializers/ContentSerializerBase.cs | Adds virtual OnKeyChange method called when a content key changes |
| uSync.Core/Serialization/Serializers/ContentSerializer.cs | Overrides OnKeyChange to invoke URL cleaner and adds it as a dependency |
| uSync.Core/Serialization/Serializers/ContentTemplateSerializer.cs | Updates constructor to accept and pass the URL cleaner to base class |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Owner
Author
|
Warning (Breaking - changes the Constructor for the |
This was referenced Feb 26, 2026
Closed
alexsee
pushed a commit
to alexsee/umbraco-container
that referenced
this pull request
Mar 7, 2026
[//]: # (dependabot-start)⚠️ **Dependabot is rebasing this PR**⚠️ Rebasing might not happen immediately, so don't worry if this takes some time. Note: if you make any changes to this PR yourself, they will take precedence over the rebase. --- [//]: # (dependabot-end) Updated [uSync](https://github.com/KevinJump/uSync) from 17.0.2 to 17.0.4. <details> <summary>Release notes</summary> _Sourced from [uSync's releases](https://github.com/KevinJump/uSync/releases)._ ## 17.0.3 This is a patch release of uSync for Umbraco v17 - it contains some fixes for reported issues. > [!NOTE] > This version supports all versions of Umbraco v17.* ## What's Changed * ⭐ Add IgnoreStopIfOnceExists setting for write-only deployments by @Copilot in KevinJump/uSync#879 * ⭐ Add cleanup in DocumentUrl tables when the content key changes. by @KevinJump in KevinJump/uSync#869 * ⭐ refresh the trees in settings when uSync finishes an import by @KevinJump in KevinJump/uSync#892 * ⭐ V17/extension example by @KevinJump in KevinJump/uSync#888 * Ensure we don't build the extend examples unless we are in debug. by @KevinJump in KevinJump/uSync#889 * 🐛 Fix - when descriptions are blank, they get filled with 'null' by @KevinJump in KevinJump/uSync#890 * 🐛 Fix - don't save 'null' in property type description name by @KevinJump in KevinJump/uSync#891 * ⬆️ update readme by @KevinJump in KevinJump/uSync#893 * ⬆️ move to centralised package management by @KevinJump in KevinJump/uSync#894 * ⬆️ update dependencies by @KevinJump in KevinJump/uSync#895 * ⬆️ add explicity JsonConverters to all enums, so they are always serialized as strings by @KevinJump in KevinJump/uSync#897 * 🆙 V17/last synced date by @KevinJump in KevinJump/uSync#898 * ⬆️ V17/object property extensions by @KevinJump in KevinJump/uSync#896 **Full Changelog**: KevinJump/uSync@v17.0.2...v17.0.4 Commits viewable in [compare view](https://github.com/KevinJump/uSync/commits). </details> Updated [uSync.Complete](https://jumoo.co.uk/uSync/complete) from 17.0.1 to 17.1.1. Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.
Workaround for umbraco/Umbraco-CMS#21131.
When a content item's Key changes during an import - Umbraco throws an ForeignKey exception because of the bindings to the
umbracoDocumentUrltable.This PR checks on key changes, and removes entries from that table (via the repository). - so the conflict doesn't happen.
On Save Umbraco puts new entries in the table with the new Key so this "should" be ok.