Bug 20089

Summary: Does Koha::Database->schema always return a connected object?
Product: Koha Reporter: Marcel de Rooy <m.de.rooy>
Component: Architecture, internals, and plumbingAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low    
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:

Description Marcel de Rooy 2018-01-25 13:33:47 UTC
My log says no:
DBD::mysql::st execute failed: MySQL server has gone away [for Statement "SELECT `me`.`variable`, `me`.`value`, `me`.`options`, `me`.`explanation`, `me`.`type` FROM `systempreferences` `me` WHERE ( `me`.`variable` = ? )" with ParamValues: 0='opacgroupresults'] at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1832.

I see them quite often, always for preferences.

Note that we do not test the cached $database->{schema} in sub schema.
If we do, we will however add some time. ( 0.0043 instead of 0.0003 )

What do you think?
Comment 1 Marcel de Rooy 2019-08-14 14:34:01 UTC
For the record:

-        return $database->{schema} if defined $database->{schema};
+        my $schema = $database->{schema};
+        if( $schema && $schema->storage->connected ) {
+            return $schema;