Bug 24148 - black magic in Circulation/Returns.t (mariadb:latest - < 10.4.11)
Summary: black magic in Circulation/Returns.t (mariadb:latest - < 10.4.11)
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Test Suite (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low normal (vote)
Assignee: Chris Cormack
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-03 15:29 UTC by Jonathan Druart
Modified: 2020-11-30 21:45 UTC (History)
1 user (show)

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


Attachments
Bug 24148: Using some black magic (995 bytes, patch)
2019-12-10 12:46 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2019-12-03 15:29:11 UTC
On the newly created job Koha_Master_D9_MDB_Latest:

koha_1       |     # Looks like you planned 2 tests but ran 1.
koha_1       | 
koha_1       | #   Failed test 'AddReturn logging on statistics table (item-level_itypes=0)'
koha_1       | #   at t/db_dependent/Circulation/Returns.t line 249.
koha_1       | Can't call method "itemtype" on an undefined value at t/db_dependent/Circulation/Returns.t line 247.

I recreate locally with this configuration (latest MariaDB version), and tried to debug:

modified: t/db_dependent/Circulation/Returns.t
@ Returns.t:245 @ subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub {
         branch     => $branch,
         type       => 'return',
         itemnumber => $item_without_itemtype->{ itemnumber }
-    }, { order_by => { -asc => 'datetime' } })->next();
+    }, { order_by => { -asc => 'datetime' } });
 
+    warn $stat->count;
+    $stat = $stat->next;

     is( $stat->itemtype, $blevel_itemtype,
         "biblio-level itype recorded on statistics for return");
 
 };

 subtest 'Handle ids duplication' => sub {


Guess what?
->count returns 1 but ->next returns undef!
Comment 1 Jonathan Druart 2019-12-10 12:46:32 UTC
Created attachment 96153 [details] [review]
Bug 24148: Using some black magic
Comment 2 Jonathan Druart 2019-12-10 13:46:46 UTC
Recreated from the MariaDB CLI.

MariaDB [koha_kohadev]> SELECT itemnumber, `type`, borrowernumber from statistics WHERE ( `itemnumber` = 1087 AND `type` = 'return' );
+------------+--------+----------------+
| itemnumber | type   | borrowernumber |
+------------+--------+----------------+
|       1087 | return |            122 |
+------------+--------+----------------+
1 row in set (0.00 sec)

MariaDB [koha_kohadev]> SELECT itemnumber, borrowernumber, datetime from statistics WHERE ( `itemnumber` = 1087 AND `type` = 'return' ) ORDER BY `datetime` ASC;
+------------+----------------+---------------------+
| itemnumber | borrowernumber | datetime            |
+------------+----------------+---------------------+
|       1087 |            122 | 2019-12-10 13:35:55 |
+------------+----------------+---------------------+
1 row in set (0.00 sec)

MariaDB [koha_kohadev]> SELECT itemnumber, borrowernumber, datetime, type from statistics WHERE ( `itemnumber` = 1087 AND `type` = 'return' ) ORDER BY `datetime` ASC;
+------------+----------------+---------------------+--------+
| itemnumber | borrowernumber | datetime            | type   |
+------------+----------------+---------------------+--------+
|       1087 |            122 | 2019-12-10 13:35:55 | return |
+------------+----------------+---------------------+--------+
1 row in set (0.00 sec)


MariaDB [koha_kohadev]> SELECT * from statistics WHERE ( `itemnumber` = 1087 AND `type` = 'return' ) ORDER BY `datetime` ASC;
Empty set (0.00 sec)

MariaDB [koha_kohadev]> SELECT * from statistics WHERE ( `itemnumber` = 1087 AND `type` = 'return' ) ORDER BY `itemnumber` ASC;
+---------------------+-----------+--------+--------+-------+------------+----------+----------+----------------+----------------------------------------------------------------------------------+
| datetime            | branch    | value  | type   | other | itemnumber | itemtype | location | borrowernumber | ccode                                                                            |
+---------------------+-----------+--------+--------+-------+------------+----------+----------+----------------+----------------------------------------------------------------------------------+
| 2019-12-10 13:35:55 | iObbbKovf | 0.0000 | return |       |       1087 | SgqzzzD  | NULL     |            122 | vghO1ljHGphe13fp_LDxGDhsYFQqTSEMJ3S2aQXYyK2gMVlo1Q3b3rpn_FQCEPKqlIgCv0iSHpc1tRdy |
+---------------------+-----------+--------+--------+-------+------------+----------+----------+----------------+----------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [koha_kohadev]> SELECT * from statistics WHERE ( `itemnumber` = 1087 AND `type` = 'return' ) ORDER BY `datetime` ASC;
Empty set (0.00 sec)

MariaDB [koha_kohadev]> SELECT itemnumber, borrowernumber from statistics WHERE ( `itemnumber` = 1087 AND `type` = 'return' ) ORDER BY `datetime` ASC;
+------------+----------------+
| itemnumber | borrowernumber |
+------------+----------------+
|       1087 |            122 |
+------------+----------------+
1 row in set (0.00 sec)
Comment 3 Jonathan Druart 2019-12-10 13:51:26 UTC
MariaDB [koha_kohadev]> SELECT  `type`, `itemnumber`  FROM `statistics` WHERE ( ( `branch` = 'iObbbKovf' AND `itemnumber` = 1087 AND `type` = 'return' ) ) ORDER BY `datetime` ASC;
+--------+------------+
| type   | itemnumber |
+--------+------------+
| return |       1087 |
+--------+------------+
1 row in set (0.00 sec)

MariaDB [koha_kohadev]> SELECT  `type`, `itemnumber`, `other`  FROM `statistics` WHERE ( ( `branch` = 'iObbbKovf' AND `itemnumber` = 1087 AND `type` = 'return' ) ) ORDER BY `datetime` ASC;
Empty set (0.00 sec)

MariaDB [koha_kohadev]> SELECT  `type`, `itemnumber`, `borrowernumber`  FROM `statistics` WHERE ( ( `branch` = 'iObbbKovf' AND `itemnumber` = 1087 AND `type` = 'return' ) ) ORDER BY `datetime` ASC;
+--------+------------+----------------+
| type   | itemnumber | borrowernumber |
+--------+------------+----------------+
| return |       1087 |            122 |
+--------+------------+----------------+
1 row in set (0.00 sec)

MariaDB [koha_kohadev]> SELECT  `type`, `itemnumber`, `itemtype`  FROM `statistics` WHERE ( ( `branch` = 'iObbbKovf' AND `itemnumber` = 1087 AND `type` = 'return' ) ) ORDER BY `datetime` ASC;
+--------+------------+----------+
| type   | itemnumber | itemtype |
+--------+------------+----------+
| return |       1087 | SgqzzzD  |
+--------+------------+----------+
1 row in set (0.00 sec)

MariaDB [koha_kohadev]> SELECT  `type`, `itemnumber`, `other`  FROM `statistics` WHERE ( ( `branch` = 'iObbbKovf' AND `itemnumber` = 1087 AND `type` = 'return' ) ) ORDER BY `itemnumber` ASC;
+--------+------------+-------+
| type   | itemnumber | other |
+--------+------------+-------+
| return |       1087 |       |
+--------+------------+-------+
1 row in set (0.00 sec)

MariaDB [koha_kohadev]> SELECT  `type`, `itemnumber`, `other`  FROM `statistics` WHERE ( ( `branch` = 'iObbbKovf' AND `itemnumber` = 1087 AND `type` = 'return' ) ) ORDER BY `borrowernumber` ASC;
Empty set (0.00 sec)
Comment 4 Jonathan Druart 2019-12-18 10:02:05 UTC
This has been fixed in our CI between run 7 (Dec 10) and 8 (Dec 11)

I do no longer recreate in a docker container with stretch and MariaDB 10.4.11
Comment 5 Jonathan Druart 2019-12-18 10:04:19 UTC
(In reply to Jonathan Druart from comment #4)
> This has been fixed in our CI between run 7 (Dec 10) and 8 (Dec 11)
> 
> I do no longer recreate in a docker container with stretch and MariaDB
> 10.4.11

Note that 10.4.11 has been released on Dec 11!

https://mariadb.com/kb/en/library/mariadb-10411-release-notes/