-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix menu item deletion #15500
Fix menu item deletion #15500
Conversation
@sarahelsaig @MikeAlhayek could you please check? |
It is best to find all references to |
@@ -270,16 +270,18 @@ public async Task<IActionResult> Delete(string menuContentItemId, string menuIte | |||
return NotFound(); | |||
} | |||
|
|||
var menuContentAsJson = (JsonObject)menu.Content; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContentElement.Content
maybe is a instance of JsonDynamicObject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, it works now. I had some notes.
src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs
Outdated
Show resolved
Hide resolved
var menuItems = menuContentAsJson[nameof(MenuItemsListPart)]["MenuItems"] as JsonArray; | ||
menuItems.Remove(menuItem); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the nitpick, but why did you use as JsonArray
here? Is it possible that this won't be here or won't be the right type? Because right now it will just cause an NRE on the next line in that scenario. I suggest either doing null-forgiving on the Remove as well (menuItems?.Remove(menuItem);
) or throwing an explicit exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I may have another problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarahelsaig updated , at #15509
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the nitpick, but why did you use
as JsonArray
here? Is it possible that this won't be here or won't be the right type? Because right now it will just cause an NRE on the next line in that scenario. I suggest either doing null-forgiving on the Remove as well (menuItems?.Remove(menuItem);
) or throwing an explicit exception.
Because there was a logical error in the last change here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my English is not good. You can debug the original code, which attempts to remove a menuId directly from a jsonObject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the nitpick, but why did you use as JsonArray here? Is it possible that this won't be here or won't be the right type? Because right now it will just cause an NRE on the next line in that scenario. I suggest either doing null-forgiving on the Remove as well (menuItems?.Remove(menuItem);) or throwing an explicit exception.
The MenuItems
is always an array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MenuItems is always an array
Thanks for the clarification.
You can debug the original code, which attempts to remove a menuId directly from a jsonObject
I've tried understanding JsonDynamicObject
. It's the same as the inner _jsonObject
, except it also has a _dictionary
. This _dictionary
field seems like a cache to me. So this could be fixed by emptying it after the json object is updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hyzx86 I've fixed it using the additional "Remove" methods from your branch. Please check out my PR (hyzx86#1003).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR does fix the problem, let's merge it, and if there are other problems, let's continue in other PR
@sarahelsaig could you please approve this PR if you don't have any objection |
@sarahelsaig @hyzx86 can we continue merging related PRs if they are ready |
Fixes #15497
/cc @sarahelsaig