Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent AutoroutePartIndex from throwing exception when content definition is not found #12567

Merged

Conversation

MikeAlhayek
Copy link
Member

@MikeAlhayek MikeAlhayek commented Oct 4, 2022

Fix #12575

@MikeAlhayek MikeAlhayek changed the title Prevent AutoroutePartIndex from throwing exception when content defined Prevent AutoroutePartIndex from throwing exception when content definition is not found Oct 5, 2022
@@ -92,7 +92,7 @@ public override async Task PublishedAsync(PublishContentContext context)

// Search for this part.
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType);
if (!contentTypeDefinition.Parts.Any(ctpd => ctpd.Name == nameof(AutoroutePart)))
if (contentTypeDefinition != null && !contentTypeDefinition.Parts.Any(ctpd => ctpd.Name == nameof(AutoroutePart)))
Copy link
Contributor

@Skrypt Skrypt Oct 6, 2022

Choose a reason for hiding this comment

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

This is an issue because then the AutoroutePart record will stay in the database and thus will keep an active route/url for that content item while it should probably dispose of the AutoroutePart record of that Content Item. But at the same time if the Content Definition has been removed then the user should not be able to make any change to that content item because it should fail to retrieve its content definition and warn about it beforehand.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't recall exact steps that lead me to this case, maybe importing from migration. Regardless, I think we should be doing null check to prevent null reference exception.

@sebastienros sebastienros merged commit a097705 into OrchardCMS:main Oct 6, 2022
@MikeAlhayek MikeAlhayek deleted the FixAutoroutePartIndexProvider branch December 28, 2022 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AutoroutePartIndex from throwing exception when content definition is not found
3 participants