Bug 12522

Summary: Fatal database error when viewing Holds for Bib with no Items
Product: Koha Reporter: David Cook <dcook>
Component: Hold requestsAssignee: David Cook <dcook>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: bgkriegel, gmcharlt, kolpen, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Attachments: Bug 12522 - Fatal database error when viewing Holds for Bib with no Items
[SIGNED-OFF] Bug 12522 - Fatal database error when viewing Holds for Bib with no Items
[PASSED QA] Bug 12522 - Fatal database error when viewing Holds for Bib with no Items

Description David Cook 2014-07-03 06:30:32 UTC
Currently, if you have the environmental variable set (via "SetEnv DEBUG 1"), you can trigger a fatal database error in the staff client by clicking "Holds" on a bib record if it has no items attached.

If you don't have DEBUG set, you'll get database error warning messages in your logs but it won't be enough to bring down Koha. 

I doubt many people are running in production with DEBUG turned on, and I doubt that many people try to view the Holds tab on a bib record that doesn't have any items.

That said, it's a good idea to reduce errors and warnings...
Comment 1 David Cook 2014-07-03 06:42:28 UTC Comment hidden (obsolete)
Comment 2 David Cook 2014-07-03 06:46:45 UTC
I suppose I should note that "Koha::get_infos_of" should probably be removed, and  "C4::Items::GetItemInfosOf", and "C4::Biblio::GetBiblioItemInfosOf" should be refactored.

(I should have probably included some explanatory comments in my patch as well, but...oh well.)
Comment 3 Owen Leonard 2014-07-03 12:36:40 UTC
*** Bug 8466 has been marked as a duplicate of this bug. ***
Comment 4 Bernardo Gonzalez Kriegel 2014-07-09 16:18:09 UTC Comment hidden (obsolete)
Comment 5 Kyle M Hall 2014-07-11 12:39:45 UTC
Created attachment 29632 [details] [review]
[PASSED QA] Bug 12522 - Fatal database error when viewing Holds for Bib with no Items

This patch fixes some potential SQL syntax errors, which can cause
fatal software errors in Koha when the environmental variable DEBUG
is on.

_TEST PLAN_

Before applying:

0) Ensure that you don't have "SetEnv DEBUG 1" in your Apache config
1) Create a new bib record
2) Click on the "Holds" tab before creating any items
3) Note the message "Cannot place hold: this record has no
items attached."

4) Add "SetEnv DEBUG 1" to your Apache config
5) Restart Apache
6) Refresh your page
7) Note the following Software Error: "DBD::mysql::st execute failed:
You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to
use near ')' at line 3 at /koha/lib/C4/Koha.pm line 835.

8) Apply the patch

9) Refresh your page
10) Note the message from Step 3

Thorough tester:

11) Remove "SetEnv DEBUG 1" from your Apache config, restart Apache,
and refresh your page. You should see the message from Step 3.

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Error reproduced, patch fixes it.
Tested following test plan, no koha-qa errors.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 6 Tomás Cohen Arazi 2014-07-14 12:03:16 UTC
Patch pushed to master.

Thanks David!