Skip to content

Conversation

@IvovdBruggen
Copy link
Contributor

@IvovdBruggen IvovdBruggen commented Mar 21, 2024

This fixes #15926

Changes

Fixes nullability of methods exposed in various Umbraco extensions.

@github-actions
Copy link

github-actions bot commented Mar 21, 2024

Hi there @IvovdBruggen, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@IvovdBruggen
Copy link
Contributor Author

Realising now that this is a very small pull request, does it sound good that I also fix all the other nullability return warnings? Excluding obsolete methods that is.

@georgebid
Copy link
Contributor

Hey @IvovdBruggen! Thank you for your PR to fix #15926, someone on the team will review this soon 😄 and in terms of creating a new issue, it's up to you really, you could either create a new one or add on to 15926, and then you could update your PR too 😄 And I agree, probably best to leave anything that is obsolete.

@IvovdBruggen IvovdBruggen changed the title Fix nullability of Children extension in FriendlyPublishedContentExtensions Fix nullability of return types that can be non-null Mar 22, 2024
@IvovdBruggen
Copy link
Contributor Author

@georgebid Great! I have updated the issue and PR and will commit the other fixes!

@georgebid georgebid self-assigned this Mar 25, 2024
@IvovdBruggen
Copy link
Contributor Author

Any progress on this perhaps? Came by the same issue today

@georgebid
Copy link
Contributor

Hey @IvovdBruggen, sorry for the delay on this one. We are doing a cleanup of older PRs, would you mind fixing the merge conflicts then we will make sure this gets reviewed, and hopefully merged! Again, sorry for the delay!

@IvovdBruggen
Copy link
Contributor Author

Hi, no problem! I'll get around to fixing the conflicts.

Ivo van der Bruggen added 2 commits January 17, 2025 21:48
# Conflicts:
#	src/Umbraco.Core/Models/Entities/EntitySlim.cs
#	src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs
#	src/Umbraco.Core/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs
#	src/Umbraco.Core/Services/FileService.cs
#	src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentSingleValueConverter.cs
#	src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs
#	src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs
#	src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs
#	src/Umbraco.Web.BackOffice/Controllers/DictionaryController.cs
#	src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs
#	src/Umbraco.Web.BackOffice/DependencyInjection/UmbracoBuilderExtensions.cs
#	src/Umbraco.Web.BackOffice/Extensions/ModelStateExtensions.cs
#	src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs
@IvovdBruggen
Copy link
Contributor Author

Hope I did the rebasing right, never did it before on a project this scale 😁

@nul800sebastiaan nul800sebastiaan changed the base branch from contrib to main May 5, 2025 12:23
# Conflicts:
#	src/Umbraco.Core/Services/ContentEditingService.cs
#	src/Umbraco.Core/Webhooks/Events/Content/ContentEmptiedRecycleBinWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Content/ContentMovedToRecycleBinWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Content/ContentMovedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Content/ContentSortedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/DocumentTypeChangedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/DocumentTypeDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/DocumentTypeMovedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/DocumentTypeSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/MediaTypeChangedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/MediaTypeDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/MediaTypeMovedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/MediaTypeSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/MemberTypeChangedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/MemberTypeDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/MemberTypeMovedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/ContentType/MemberTypeSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/DataType/DataTypeDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/DataType/DataTypeMovedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/DataType/DataTypeSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Dictionary/DictionaryItemDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Dictionary/DictionaryItemSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Domain/DomainDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Domain/DomainSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/File/PartialViewDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/File/PartialViewSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/File/ScriptDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/File/ScriptSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/File/StylesheetDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/File/StylesheetSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/File/TemplateDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/File/TemplateSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Language/LanguageDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Language/LanguageSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Member/ExportedMemberWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Member/MemberDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Member/MemberGroupDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Member/MemberGroupSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Member/MemberSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/PublicAccess/PublicAccessEntryDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/PublicAccess/PublicAccessEntrySavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Relation/RelationDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/Relation/RelationSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/RelationType/RelationTypeDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/RelationType/RelationTypeSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/User/AssignedUserGroupPermissionsWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/User/UserDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/User/UserGroupDeletedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/User/UserGroupSavedWebhookEvent.cs
#	src/Umbraco.Core/Webhooks/Events/User/UserSavedWebhookEvent.cs
#	src/Umbraco.Infrastructure/PropertyEditors/TrueFalsePropertyEditor.cs
#	src/Umbraco.PublishedCache.HybridCache/DocumentCache.cs
#	src/Umbraco.PublishedCache.HybridCache/MediaCache.cs
#	src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs
…property editors (whilst some property editors we know won't return null, it seems more consistent to adhere to the base class and interface nullability definition).
@AndyButland
Copy link
Contributor

AndyButland commented Jul 23, 2025

Thanks for the efforts on this @IvovdBruggen. I've had a look at resurrecting it - I know it's been a while, but there are some nice updates in here that I agree would be good to include.

I've pushed a few updates in case you'd like to comment:

  • Merged latest from main.
  • Reverted a few updates that meant we had different nullability for return types on the implementation and the interface or base class. Whilst the implementations of for example particularly property value converters may be marked as not returning null, it felt to me that it was better to be consistent with the interface or base class.
  • In other cases though, it did seem better to make the nullability change to the interface too - particularly for collections. It's better practice here to return empty collections over null values. So I've done that too.

For the latter case this will mean breaking changes, so it'll be best to include this for Umbraco 17.

I'll take this to the team in HQ to get some further opinions on how best to handle this, but assuming you agree with the changes, we could re-target this to v17/dev and include for the next major release.

@IvovdBruggen
Copy link
Contributor Author

Hi @AndyButland, thanks for taking a look! I am currently on holiday but what you say seems good. As for Umbraco 17 release, thats good. At the moment I don't work alot with Umbraco so whenever's good.

@AndyButland AndyButland changed the base branch from main to v17/dev July 30, 2025 11:34
# Conflicts:
#	src/Umbraco.Core/Services/AuditService.cs
Copilot AI review requested due to automatic review settings July 30, 2025 11:40
Copy link
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 nullability annotations for return types across the Umbraco codebase that were incorrectly marked as nullable when they can actually return non-null values. The changes ensure proper type safety and better developer experience by correctly indicating when methods will always return non-null values.

Key changes:

  • Remove nullable annotations (?) from return types that never return null
  • Update method signatures in interfaces and implementations to match
  • Fix inconsistencies between base classes and derived classes

Reviewed Changes

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

Show a summary per file
File Description
Various webhook event classes Remove nullable return types from ConvertNotificationToRequestPayload methods that always return objects
Extension classes Remove nullable annotations from methods like Name, Children, Siblings that return non-null collections/strings
Service interfaces and implementations Fix return types for methods like GetActiveServers, GetMembersByPropertyValue that return non-null collections
Property value converters Correct nullability of conversion methods based on actual return behavior
Utility and extension classes Update return types for helper methods that guarantee non-null results

@AndyButland
Copy link
Contributor

Thanks again @IvovdBruggen - as mentioned above, we'll merge this in but keep it for Umbraco 17 due to the minor breaking changes introduced by these nullability updates.

@AndyButland AndyButland enabled auto-merge (squash) July 30, 2025 12:18
@AndyButland AndyButland merged commit c3e93f1 into umbraco:v17/dev Jul 30, 2025
25 checks passed
@ronaldbarendse
Copy link
Contributor

@AndyButland Removing nullability from the abstract/virtual WebhookEventBase<TNotification>.ConvertNotificationToRequestPayload() return type should be reverted, because although the CMS never returns a null value in its own concrete implementations, other implementations might. Also IWebhookFiringService.FireAsync() still accepts a nullable payload, so it should be valid to return null from this method, right?

@AndyButland
Copy link
Contributor

Thanks @ronaldbarendse - I've addressed with #20660.

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.

Incorrect nullable return values throughout various classes

6 participants