Skip to content

Relations: Swallow exceptions when retrieving references from incompatible property values (closes #22197)#22207

Merged
AndyButland merged 4 commits intomainfrom
v17/bugfix/22197-fix-safe-retrieval-of-references
Apr 22, 2026
Merged

Relations: Swallow exceptions when retrieving references from incompatible property values (closes #22197)#22207
AndyButland merged 4 commits intomainfrom
v17/bugfix/22197-fix-safe-retrieval-of-references

Conversation

@AndyButland
Copy link
Copy Markdown
Contributor

@AndyButland AndyButland commented Mar 20, 2026

Description

#22197 reports an error when a data type is changed to a new property editor, incompatible with previously stored property values. An exception is thrown in trying to retrieve references from the incorrect JSON data.

We actually addressed this before. PR #18576 added a try/catch around reference retrieval specifically to handle the scenario where a property editor on a data type is changed and existing stored values are incompatible with the new editor. However, despite the comment in the catch block saying "Log the exception but don't throw, continue with the next value", the code contained throw; on the next line, re-throwing the exception after logging it. This meant the protection never actually worked.

So this PR corrects that, handles a missing case for the GetReferencesFromPropertyValues method, and adds unit tests verifying that incompatible property values do not propagate exceptions.

Additional Fix

In testing I found the scenario outlined in the test steps below would log an exception as expected, but the property was still not editable. The blocks JSON was still be returned to the multi-URL picker client side property editor, which would crash as it got data it wasn't expecting.

This happened because the MultiUrlPickerValueEditor.ToEditor() catch block previously fell back to base.ToEditor(), which deserializes the incompatible value as a dynamic JSON

I changed the fallback to return Enumerable.Empty<object>() (matching the existing empty-value behaviour), so the
property renders as empty and allows the user to enter new values.

Testing

Automated

  • 4 new unit tests in DataValueReferenceFactoryCollectionTests covering both the editor and factory paths, including continuation after a throwing value. These tests fail before the fix is applied.

Manual

  1. Create a document type with a Block List property.
  2. Create content using the document type, adding data to the Block List property, and publish.
  3. Change the Block List property on the document type to a Multi URL Picker.
  4. Open the content item in the backoffice — the property should render (empty/blank is fine for the new editor).
  5. Save the content — before this fix the save fails with a JsonException; after this fix the save succeeds (a warning is logged but the operation completes).
  6. Verify the log contains the Error getting references from value message at Error level.

Copilot AI review requested due to automatic review settings March 20, 2026 08:13
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 fixes reference-tracking robustness in DataValueReferenceFactoryCollection by ensuring exceptions from incompatible stored property values are logged and swallowed (instead of being re-thrown), preventing relation/reference lookups from blocking operations like save/publish when editors change.

Changes:

  • Removed an unintended throw; that re-threw exceptions after logging during reference extraction.
  • Routed the IDataValueReferenceFactory path through the same per-value try/catch helper used for IDataValueReference editors.
  • Added unit tests covering both editor and factory paths, including continuation after a throwing value.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollection.cs Ensures exceptions during reference extraction are consistently swallowed for both editor- and factory-based reference resolution.
tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollectionTests.cs Adds regression tests to verify incompatible values don’t propagate exceptions and that processing continues for subsequent values.

@AndyButland AndyButland merged commit 65b85fd into main Apr 22, 2026
28 checks passed
@AndyButland AndyButland deleted the v17/bugfix/22197-fix-safe-retrieval-of-references branch April 22, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants