[Bug 44339] New: Template plugin Categories.GetName dies for a category code that does not exist
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44339 Bug ID: 44339 Summary: Template plugin Categories.GetName dies for a category code that does not exist Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Templates Assignee: oleonard@myacpl.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org Target Milestone: --- The Categories template plugin (Koha/Template/Plugin/Categories.pm) has a GetName method that does Koha::Patron::Categories->find($categorycode)->description. When no category has that code, find returns undef and the page dies with: Can't call method "description" on an undefined value. The code is not always one that exists. It can come from user input, such as a category filter in the URL of a statistics report, or from data that no longer matches a category. A page that displays it then ends in a 500 error instead of showing what was asked for. The sibling plugins do not behave like this: Branches.GetName returns an empty value for a library that does not exist, and the authorised values plugin does not die either. Found while testing bug 42737, where it was worked around in that report only, as this plugin is shared by many pages and changing it deserves its own bug. Test plan: 1. In the staff interface go to Reports > Circulation (statistics wizard) 2. Choose Library as the line, Item type as the column, Checkouts as the type of activity, choose a patron category in the Patron category filter, and submit: the report is displayed 3. In the URL change the value of the category filter (the third Filter parameter) to ZZZ and load the page 4. Note the 500 error: Can't call method "description" on an undefined value 5. Apply the patch and restart_all, and load the same URL again 6. Note the report is displayed, with ZZZ as the patron category -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44339 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 212801 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212801&action=edit Bug 44339: Do not die in Categories.GetName for an unknown category Koha::Template::Plugin::Categories->GetName did find($categorycode)->description, which dies with "Can't call method description on an undefined value" for a category code that does not exist. The code can come from user input, such as the category filter in the URL of a statistics report, or from data that no longer matches a category, and the page then ended in a 500 error. Return the code itself when there is no such category, and an empty value when there is no code, like the plugin for libraries does. Test plan: 1. In the staff interface go to Reports > Circulation (statistics wizard) 2. Choose Library as the line, Item type as the column, Checkouts as the type of activity, a patron category in the Patron category filter, and submit: the report is displayed 3. In the URL change the value of the category filter (the third Filter parameter) to ZZZ and load the page => Without this patch: a 500 error, Can't call method "description" on an undefined value => With it: the report is displayed, with ZZZ as the patron category 4. prove t/db_dependent/Template/Plugin/Categories.t Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org