Skip to content

Add cleanup in DocumentUrl tables when the content key changes.#869

Merged
KevinJump merged 1 commit intov17/mainfrom
v17/key-url-cleanup
Feb 19, 2026
Merged

Add cleanup in DocumentUrl tables when the content key changes.#869
KevinJump merged 1 commit intov17/mainfrom
v17/key-url-cleanup

Conversation

@KevinJump
Copy link
Copy Markdown
Owner

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 umbracoDocumentUrl table.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ISyncDocumentUrlCleaner interface and SyncDocumentUrlCleaner implementation to handle DocumentUrl table cleanup
  • Added OnKeyChange virtual method in ContentSerializerBase to allow subclasses to respond to key changes
  • Integrated URL cleaning into ContentSerializer when 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.

Comment thread uSync.Core/Serialization/Serializers/ContentSerializer.cs
Comment thread uSync.Core/Documents/SyncDocumentUrlCleaner.cs
Comment thread uSync.Core/uSyncCoreBuilderExtensions.cs
Comment thread uSync.Core/Documents/SyncDocumentUrlCleaner.cs
@KevinJump KevinJump added the Breaking Change A Change that might impact 3rd party code, or change the format of export files label Dec 15, 2025
@KevinJump
Copy link
Copy Markdown
Owner Author

KevinJump commented Dec 15, 2025

Warning

(Breaking - changes the Constructor for the ContentSerializer class)

@KevinJump KevinJump merged commit bf467b9 into v17/main Feb 19, 2026
10 checks passed
@KevinJump KevinJump deleted the v17/key-url-cleanup branch February 19, 2026 13:23
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking Change A Change that might impact 3rd party code, or change the format of export files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants