Bug 32674 - When placing a hold in OPAC page explodes into error 500
Summary: When placing a hold in OPAC page explodes into error 500
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: Main
Hardware: All All
: P5 - low critical (vote)
Assignee: Jonathan Druart
QA Contact: Katrin Fischer
URL:
Keywords:
: 33081 (view as bug list)
Depends on: 31306
Blocks:
  Show dependency treegraph
 
Reported: 2023-01-18 16:16 UTC by Katrin Fischer
Modified: 2023-12-28 20:43 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00,22.11.04


Attachments
Bug 32674: Fix placing a hold at the OPAC for serials (1.15 KB, patch)
2023-02-28 08:15 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 32674: Fix placing a hold at the OPAC for serials (1.20 KB, patch)
2023-02-28 09:59 UTC, Janusz Kaczmarek
Details | Diff | Splinter Review
Bug 32674: Fix placing a hold at the OPAC for serials (1.26 KB, patch)
2023-03-04 15:10 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 32674: Fix placing a hold at the OPAC for serials (1.29 KB, patch)
2023-03-04 15:11 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Katrin Fischer 2023-01-18 16:16:16 UTC
When trying to place a hold on a record in the OPAC, we get an error 500 in 22.11.01.

The error in the logs is:

DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Column 'biblionumber' in where clause is ambiguous at /usr/share/koha/lib/Koha/Objects.pm line 394

With Joubu's help we tested following change that fixes the issue:

opac/opac-reserve.pl, L.338

-  biblionumber => $biblioNumber,
+  "me.biblionumber" => $biblionumber,


There is no test plan as we haven't figured out yet, why this happens for some records and not for others. Items and records look normal, no hidden items on the record and no 773 etc. :)
Comment 1 Jonathan Druart 2023-01-18 16:22:31 UTC Comment hidden (obsolete)
Comment 2 Jonathan Druart 2023-01-18 16:28:26 UTC
opac-detail.pl has 'me.biblionumber' => $biblionumber.
Comment 3 Katrin Fischer 2023-01-18 16:55:36 UTC
To maybe find out more of what's going on:


* Try emptying out OpacHiddenItems to see if it makes a difference
* Try toggling hidelostitems
* Get to the SQL query (hope I got these right):

Change Koha/Database.pm:

 sub _new_schema {

+    $ENV{DBIC_TRACE} = 1;

restart plack
tail -f the log
hit the page/create the error
remove the DBIC_TRACE
restart plack
Comment 4 Thomas Klausner 2023-01-18 20:00:05 UTC
Just a general DBIC-note: This problem is caused when joining tables and both tables have a column with the same name. As DBIC allows chaining of result-set/search calls, a given piece of code may work in one case, but not when later own the base query is amended and eg a second table is joined.

Therefore it's (IMO) best pratice to always use the `me.` alias in DBIC searches, just to future-proof your code.
Comment 5 Jonathan Druart 2023-02-28 08:13:13 UTC
There are more info on bug 33081, it's happening for serials.
Comment 6 Jonathan Druart 2023-02-28 08:13:17 UTC
*** Bug 33081 has been marked as a duplicate of this bug. ***
Comment 7 Jonathan Druart 2023-02-28 08:15:05 UTC
Created attachment 147479 [details] [review]
Bug 32674: Fix placing a hold at the OPAC for serials

Placing a hold at the OPAC explodes with a 500 when the record is a
serial
DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Column 'biblionumber' in where clause is ambiguous at /usr/share/koha/lib/Koha/Objects.pm line 394

Test plan:
Create a serial from a given biblio
Place a hold on this record at the OPAC
Comment 8 Janusz Kaczmarek 2023-02-28 08:59:50 UTC
Jonathan, thank you for identifying the duplicate. 

I wonder also if the first argument to search_ordered call should not be a anon. hash, like:


     my $items = Koha::Items->search_ordered(
         {
         -or =>
         [
             'me.biblionumber' => $biblioNumber,
             'me.itemnumber' => {
                 -in => [
.....
        ],
        },

since it is than passed to search?  This would have been in my patch which I did not manage to send yesterday.
Comment 9 Jonathan Druart 2023-02-28 09:32:41 UTC
(In reply to Janusz Kaczmarek from comment #8)
> Jonathan, thank you for identifying the duplicate. 
> 
> I wonder also if the first argument to search_ordered call should not be a
> anon. hash, like:
> 
> 
>      my $items = Koha::Items->search_ordered(
>          {
>          -or =>
>          [
>              'me.biblionumber' => $biblioNumber,
>              'me.itemnumber' => {
>                  -in => [
> .....
>         ],
>         },
> 
> since it is than passed to search?  This would have been in my patch which I
> did not manage to send yesterday.

They are identical constructs, it won't change anything.
Comment 10 Janusz Kaczmarek 2023-02-28 09:59:39 UTC
Created attachment 147481 [details] [review]
Bug 32674: Fix placing a hold at the OPAC for serials

Placing a hold at the OPAC explodes with a 500 when the record is a
serial
DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Column 'biblionumber' in where clause is ambiguous at /usr/share/koha/lib/Koha/Objects.pm line 394

Test plan:
Create a serial from a given biblio
Place a hold on this record at the OPAC

Signed-off-by: Janusz Kaczmarek <januszop@gmail.com>
Comment 11 Jonathan Druart 2023-02-28 10:25:43 UTC
> Signed-off-by: Janusz Kaczmarek <januszop@gmail.com>

Did you forget to change the status? :)
Comment 12 Katrin Fischer 2023-03-04 15:10:29 UTC
Created attachment 147759 [details] [review]
Bug 32674: Fix placing a hold at the OPAC for serials

Placing a hold at the OPAC explodes with a 500 when the record is a
serial
DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Column 'biblionumber' in where clause is ambiguous at /usr/share/koha/lib/Koha/Objects.pm line 394

Test plan:
* Create a subscription for an existing bibliographic record
* Place a hold on this record at the OPAC

Signed-off-by: Janusz Kaczmarek <januszop@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 13 Katrin Fischer 2023-03-04 15:11:16 UTC
Created attachment 147760 [details] [review]
Bug 32674: Fix placing a hold at the OPAC for serials

Placing a hold at the OPAC explodes with a 500 when the record is a
serial
DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Column 'biblionumber' in where clause is ambiguous at /usr/share/koha/lib/Koha/Objects.pm line 394

Test plan:
* Create a serial subscription for an existing bibliographic record
* Place a hold on this record at the OPAC

Signed-off-by: Janusz Kaczmarek <januszop@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 14 Tomás Cohen Arazi 2023-03-06 12:48:58 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 15 Jacob O'Mara 2023-03-07 18:27:55 UTC
Nice work, thanks everyone!

Pushed to 22.11.x for the next release.
Comment 16 Lucas Gass 2023-03-10 16:29:09 UTC
Missing dependencies for 22.05.x