Skip to content

Relations: Allow Element and ElementContainer as allowed object types for relation creation#23217

Merged
AndyButland merged 1 commit into
mainfrom
v18/bugfix/relationtype-allow-element-objecttypes
Jun 29, 2026
Merged

Relations: Allow Element and ElementContainer as allowed object types for relation creation#23217
AndyButland merged 1 commit into
mainfrom
v18/bugfix/relationtype-allow-element-objecttypes

Conversation

@ronaldbarendse

Copy link
Copy Markdown
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #23216

Description

v18 seeds three built-in element relation types (parent/child object types Element / ElementContainer) directly into the database via DatabaseDataCreator (install) and the V_18_0_0.AddElements migration (upgrade), bypassing IRelationService. But RelationService.SaveAsync validates object types against GetAllowedObjectTypes(), which never had Element/ElementContainer added. As a result the service rejects any CreateAsync/UpdateAsync of these relation types with InvalidParentObjectType/InvalidChildObjectType — breaking the backoffice Relations list and Umbraco Deploy import/transfer (which re-saves built-in relation types through the service).

This adds Element and ElementContainer to GetAllowedObjectTypes().

How to test:

  1. On a clean 18.0.0 install, resolve IRelationService, load relateParentElementContainerOnElementDelete via GetRelationTypeByAlias, and call UpdateAsync — it now returns RelationTypeOperationStatus.Success (previously InvalidParentObjectType).
  2. Or run the added integration tests: Can_Create_Relation_Types_With_Allowed_Object_Types now covers ElementContainerElement and ElementContainerElementContainer.

Changes:

  • src/Umbraco.Core/Services/RelationService.cs — add UmbracoObjectTypes.Element and UmbracoObjectTypes.ElementContainer to the allowed set.
  • tests/Umbraco.Tests.Integration/.../RelationServiceTests.cs — two new test cases.

Copilot AI review requested due to automatic review settings June 26, 2026 14:14
@claude

claude Bot commented Jun 26, 2026

Copy link
Copy Markdown

Claude finished @ronaldbarendse's task in 2m 45s —— View job


PR Review

Target: origin/main · Based on commit: 1d4d3842

Adds UmbracoObjectTypes.Element and UmbracoObjectTypes.ElementContainer to RelationService.GetAllowedObjectTypes(), allowing v18's seeded element relation types (relateParentElementContainerOnElementDelete, relateParentElementContainerOnContainerDelete) to be saved through IRelationService without returning InvalidParentObjectType/InvalidChildObjectType.

  • Other changes: The ObjectTypePresentationFactory consumer of GetAllowedObjectTypes() will now also include Element and ElementContainer in the object-type picker response returned to the backoffice — this is the intended behavior and correctly aligns with what the migration seeds directly into the database.

No Critical or Important issues found. No breaking changes — the change is purely additive.

Suggestions

  • tests/.../RelationServiceTests.cs:52-53: Both new test cases cover the child–parent direction used by the two seeded relation types. Adding a case with Element as parent (e.g. ElementElement) would widen coverage slightly, but it is not required for correctness and the existing cases are sufficient to validate the fix.

Approved

The fix is minimal, targeted, and correct. The two new integration test cases directly mirror the seeded relation types introduced in V_18_0_0/AddElements.cs, which is exactly the right regression harness. Good to merge.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 a validation gap in IRelationService by allowing the new v18 element object types (Element, ElementContainer) to be used when creating/updating relation types via RelationService, aligning service validation with the relation types seeded by install/migrations.

Changes:

  • Extend RelationService.GetAllowedObjectTypes() to include UmbracoObjectTypes.Element and UmbracoObjectTypes.ElementContainer.
  • Expand integration test coverage to assert relation types can be created with ElementContainer → Element and ElementContainer → ElementContainer object type combinations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Umbraco.Core/Services/RelationService.cs Adds Element/ElementContainer to the allowed object type set used by relation type validation.
tests/Umbraco.Tests.Integration/Umbraco.Core/Services/RelationServiceTests.cs Adds two integration test cases covering the newly-allowed element relation type combinations.

@claude claude Bot added the area/backend label Jun 26, 2026
@sonarqubecloud

Copy link
Copy Markdown

@AndyButland AndyButland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @ronaldbarendse, looks good and a clear oversight/fix.

I'll label this for 18.1 for now, as it'll definitely be in that, but likely bring forward to 18.0.1 if and when we arrange a patch release.

@AndyButland AndyButland changed the title Fix: allow Element and ElementContainer object types in RelationService Relations: Allow Element and ElementContainer as allowed object types for relation creation Jun 29, 2026
@AndyButland AndyButland merged commit ae0837d into main Jun 29, 2026
34 checks passed
@AndyButland AndyButland deleted the v18/bugfix/relationtype-allow-element-objecttypes branch June 29, 2026 11:44
pull Bot pushed a commit to steelburn/Umbraco-CMS that referenced this pull request Jul 1, 2026
…ypes for relation creation (umbraco#23217)

Allow Element and ElementContainer object types in RelationService
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.

RelationService rejects the built-in element relation types (Element/ElementContainer not in allowed object types)

3 participants