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

Fixed StackOverflow exception when using NoopPropertyIndexValueFactory #15284

Merged

Conversation

geann
Copy link
Contributor

@geann geann commented Nov 22, 2023

Prerequisites

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

This is related to the issue #14556, which has been partially fixed for RichTextPropertyEditor, but not for property editors that use NoopPropertyIndexValueFactory.

Description

Removed recursive call from the GetIndexValues method of NoopPropertyIndexValueFactory which is now marked as obsolete. Even though it is an obsolete method and it is not directly called within Umbraco CMS codebase anymore, I thought it would be good to fix it for backward compatibility with modules and libraries that may be still using it, for example https://github.com/umbraco/Umbraco.Cms.Integrations.

This is how this method looked prior to this change, see the recursive call in red:
Recursive call

Instead of making a recursive call it now calls the other method overload with 5 parameters, as seen in other property index value factory classes (DefaultPropertyIndexValueFactory, JsonPropertyIndexValueFactoryBase, GridPropertyIndexValueFactory and RichTextPropertyIndexValueFactory).

Steps to reproduce

I've tried it with Umbraco 12.2.0/12.3.0 and Umbraco.Cms.Integrations.Search.Algolia library version 1.5.0.

  1. Install the package Umbraco.Cms.Integrations.Search.Algolia.
  2. Configure an index with at least one content type and include a field of the type Umbraco.MediaPicker3.
  3. Make a change to a document of this content type and save it. The application will crash with StackOverflowException:
Stack overflow.
Repeat 23771 times:
--------------------------------
   at Umbraco.Cms.Core.PropertyEditors.NoopPropertyIndexValueFactory.GetIndexValues(Umbraco.Cms.Core.Models.IProperty, System.String, System.String, Boolean)
--------------------------------
   at Umbraco.Cms.Integrations.Search.Algolia.Services.AlgoliaSearchPropertyIndexValueFactory.GetValue(Umbraco.Cms.Core.Models.IProperty, System.String)
   at Umbraco.Cms.Integrations.Search.Algolia.Builders.ContentRecordBuilder.BuildFromContent(Umbraco.Cms.Core.Models.IContent, System.Func`2<Umbraco.Cms.Core.Models.IProperty,Boolean>)
   at Umbraco.Cms.Integrations.Search.Algolia.Handlers.AlgoliaContentCacheRefresherHandler+<RebuildIndex>d__10.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Umbraco.Cms.Integrations.Search.Algolia.Handlers.AlgoliaContentCacheRefresherHandler+<RebuildIndex>d__10, Umbraco.Cms.Integrations.Search.Algolia, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null]](<RebuildIndex>d__10 ByRef)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Umbraco.Cms.Integrations.Search.Algolia.Handlers.AlgoliaContentCacheRefresherHandler+<RebuildIndex>d__10, Umbraco.Cms.Integrations.Search.Algolia, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null]](<RebuildIndex>d__10 ByRef)
   at Umbraco.Cms.Integrations.Search.Algolia.Handlers.AlgoliaContentCacheRefresherHandler.RebuildIndex(System.Collections.Generic.IEnumerable`1<Umbraco.Cms.Core.Models.IContent>)
   at Umbraco.Cms.Integrations.Search.Algolia.Handlers.AlgoliaContentCacheRefresherHandler+<HandleAsync>d__9.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Umbraco.Cms.Integrations.Search.Algolia.Handlers.AlgoliaContentCacheRefresherHandler+<HandleAsync>d__9, Umbraco.Cms.Integrations.Search.Algolia, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null]](<HandleAsync>d__9 ByRef)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Umbraco.Cms.Integrations.Search.Algolia.Handlers.AlgoliaContentCacheRefresherHandler+<HandleAsync>d__9, Umbraco.Cms.Integrations.Search.Algolia, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null]](<HandleAsync>d__9 ByRef)
   at Umbraco.Cms.Integrations.Search.Algolia.Handlers.AlgoliaContentCacheRefresherHandler.HandleAsync(Umbraco.Cms.Core.Notifications.ContentCacheRefresherNotification, System.Threading.CancellationToken)
   at Umbraco.Cms.Core.Events.INotificationAsyncHandler`1+<HandleAsync>d__1[[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
...

I have previously raised an issue in umbraco/Umbraco.Cms.Integrations#150 to remove the obsolete method call, but then realised that there could be other packages using this method and it would be good to fix this method until it's fully deprecated in v14.

Removed recursive call from the GetIndexValues method of NoopPropertyIndexValueFactory for backward compatibility and alignment with other property index value factory classes
Copy link

github-actions bot commented Nov 22, 2023

Hi there @geann, 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 🤖 🙂

@JasonElkin
Copy link
Contributor

Hello @geann

Thanks for contributing a fix for this exception 👍
Someone from the core collaborators team will take a look at it soon.

Cheers!

@mikecp
Copy link
Contributor

mikecp commented Feb 13, 2024

Hi @geann,

Thank you for this fix and for keeping this deprecated method from crashing until it's actually removed 👍
Let's merge this and get things stable again 😁

I see this is your first contribution to Umbraco, congratulations!! 🎉
If you provide us with your account name on Our, my teammate @nul800sebastiaan will be more than happy to assign our shiny contributor's badge to you 🏅

We'll be looking forward to your next contributions!

Cheers!

@mikecp mikecp merged commit 37d96db into umbraco:contrib Feb 13, 2024
14 of 15 checks passed
@geann
Copy link
Contributor Author

geann commented Feb 13, 2024

Hi @mikecp, great news, thanks for merging and closing this one! 🙌
Glad it was helpful, my account name on Our is geann 😊
Cheers!

@nul800sebastiaan
Copy link
Member

Thanks again and congrats on you contributor badge! 🥇

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.

4 participants