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

[OMP] Fatal error when creating a series menu item without content #10511

Closed
jonasraoni opened this issue Oct 8, 2024 · 13 comments · Fixed by pkp/omp#1763 or pkp/omp#1772
Closed

[OMP] Fatal error when creating a series menu item without content #10511

jonasraoni opened this issue Oct 8, 2024 · 13 comments · Fixed by pkp/omp#1763 or pkp/omp#1772
Assignees
Labels
Bug:1:Low A bug that does not have a severe consequence or affects a small number of users.
Milestone

Comments

@jonasraoni
Copy link
Contributor

jonasraoni commented Oct 8, 2024

Describe the bug
After creating a series menu item without linking it to any item (see image below), a fatal error happens.

image

PHP Fatal error:  Uncaught TypeError: PKP\section\Repository::get(): Argument #1 ($id) must be of type int, string given, called in classes/services/NavigationMenuService.php on line 157 and defined in lib/pkp/classes/section/Repository.php:58
Stack trace:
#0 classes/services/NavigationMenuService.php(157): PKP\section\Repository->get()
#1 [internal function]: APP\services\NavigationMenuService->getDisplayStatusCallback()
#2 lib/pkp/classes/plugins/Hook.php(139): call_user_func_array()
#3 lib/pkp/classes/plugins/Hook.php(113): PKP\plugins\Hook::run()
#4 lib/pkp/classes/services/PKPNavigationMenuService.php(382): PKP\plugins\Hook::call()

The strange thing that needs to be analyzed is that a call to $navigationMenuItem->getPath() outputs Laravel code �*�escapeWhenCastingToString.

A workaround must be left for bad cases, and the field should be probably turned into required. If the ID is a physical field, it can be setup as not null, but a further script should clear invalid data on the upgrade.

It's also needed to check if the bug applies to OMP 3.3

To Reproduce

  1. Create a series menu item, like in the sample image
  2. Add it to the navigation
  3. See the error

What application are you using?
OMP 3.4

Pull requests

@jonasraoni jonasraoni added the Bug:1:Low A bug that does not have a severe consequence or affects a small number of users. label Oct 8, 2024
@jonasraoni jonasraoni added this to the 3.4.0-x milestone Oct 8, 2024
YvesLepidus added a commit to lepidus/omp that referenced this issue Nov 14, 2024
…rt a menu item with the series type.

Signed-off-by: yves <[email protected]>
@YvesLepidus
Copy link
Contributor

Hi @jonasraoni ! 😃
I've created a PR to fix the display of series without content when creating a series-type menu item, even when there are series enabled in OMP 3.4.
I think this may also fix this fatal error, given that it is not possible to add a series-type menu item when there are no series registered in OMP.

@jonasraoni
Copy link
Contributor Author

I've checked your PR and it makes sense, I'll update and approve it.

Nevertheless, I'll leave this issue open, it might be possible to create a menu without series yet (e.g. if you create the menu before creating a series) and there's also the people who already have a bad menu on the database.

@kaitlinnewson
Copy link
Member

@jonasraoni I tested how it works when no series are present, and there is no option to create a series menu if no series exists, so that case already seems to be covered.

@jonasraoni
Copy link
Contributor Author

Great, so there's just one thing to fix, the existing bad records.

YvesLepidus added a commit to lepidus/omp that referenced this issue Nov 18, 2024
…map with keys.

Co-authored-by: Jonas Raoni Soares da Silva <[email protected]>
@kaitlinnewson kaitlinnewson self-assigned this Nov 22, 2024
kaitlinnewson added a commit to pkp/omp that referenced this issue Nov 22, 2024
pkp/pkp-lib#10511 menu item of type series without content even when they exist in the OMP 3.4
@kaitlinnewson
Copy link
Member

Thanks @YvesLepidus! Your PR is now merged to 3.4, and I can cherry-pick this to main for the 3.5 release and work on the issue with bad records.

@kaitlinnewson kaitlinnewson modified the milestones: 3.4.0-x, 3.4.0-8 Nov 22, 2024
@jonasraoni
Copy link
Contributor Author

@kaitlinnewson I was going to handle this one, but as you've self-assigned, please take a look at the The strange thing that needs to be analyzed is that a call to $navigationMenuItem->getPath() outputs Laravel code �*�escapeWhenCastingToString..

Basically, setup a bad menu, then check this line:
https://github.com/pkp/omp/blob/ef4fa4e98015d2af1f7b47dae3dad9e39198e17f/classes/services/NavigationMenuService.php#L156

If you can't reproduce, great 😂

@kaitlinnewson
Copy link
Member

kaitlinnewson commented Nov 22, 2024

@jonasraoni I think this is happening when Smarty is trying to convert the Collection objects into strings but failing. With the bad code, this error is logged when creating the bad series menu item:

[Fri Nov 22 10:26:35 2024] PHP Notice: html_options: value is an object of class 'Closure' without __toString() method in /Users/kaitlinnewson/Code/omp-3_4_0/lib/pkp/lib/vendor/smarty/smarty/libs/plugins/function.html_options.php on line 184

...and this is a snippet of what gets rendered in the HTML with the bad code:

<label for="seriesSelect">Select Series</label>						
<div>
<select id="relatedSeriesId" name="relatedSeriesId" required="" aria-required="true" aria-invalid="false">
    <option value="�*�escapeWhenCastingToString"></option>
</select>

... and as a result of this, �*�escapeWhenCastingToString is written to the database as the path value in navigation_menu_items, so that is what is being returned by getPath().

Is anything needed beyond removing the bad entries?

@jonasraoni
Copy link
Contributor Author

Okay, just wanted to make sure there's nothing strange under the hood 🥲

Well, I see two ways:
A. Remove the invalid entries, to honor the "required" expectation.
B. Ensure such entries are skipped/do not fail, and make the series not required.

Going further, what happens when a linked series is removed? I'm almost sure it's going to leave orphaned entries behind (which should probably be fixed as well), and I guess the same might happen with other types of menus that are linked against database entities.

kaitlinnewson pushed a commit to kaitlinnewson/omp that referenced this issue Nov 22, 2024
…rt a menu item with the series type.

Signed-off-by: yves <[email protected]>
kaitlinnewson pushed a commit to kaitlinnewson/omp that referenced this issue Nov 22, 2024
…map with keys.

Co-authored-by: Jonas Raoni Soares da Silva <[email protected]>
kaitlinnewson added a commit to kaitlinnewson/omp that referenced this issue Nov 22, 2024
kaitlinnewson added a commit to kaitlinnewson/omp that referenced this issue Nov 22, 2024
@kaitlinnewson
Copy link
Member

I think it's better to remove them, because if they are assigned to a menu they produce a fatal error and blank white screen on the page where the menu is assigned (so they aren't usable at all).

I can test the other scenario you mentioned, and file another issue for that if I find issues with orphaned entries when a series is deleted.

@asmecher
Copy link
Member

(The �*� in �*�escapeWhenCastingToString is what you get when PHP serializes a private/protected attribute. Reference)

@jonasraoni
Copy link
Contributor Author

jonasraoni commented Nov 25, 2024

Just to confirm, I deleted a series and the menu was kept, I guess other "entity links" might have the same issue (#10633).

And I think it's worth to fix the origin of the issue (the TypeError), which can be done by coercing the getPath() calls to an integer where suitable.

@asmecher
Copy link
Member

@kaitlinnewson and @jonasraoni, this appears to have been merged/fixed in 3.4.0 but not main, correct? I'm wrapping up the 3.4.0-8 release and want to make sure I get the release notes accurately.

@kaitlinnewson
Copy link
Member

@asmecher yes, this is merged for stable-3_4_0 but in review for main.

@asmecher asmecher modified the milestones: 3.4.0-8, 3.5 Internal Nov 29, 2024
jonasraoni added a commit to pkp/omp that referenced this issue Nov 29, 2024
 pkp/pkp-lib#10511 fix and cleanup invalid series navigation menu items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug:1:Low A bug that does not have a severe consequence or affects a small number of users.
Projects
None yet
4 participants