Bug 29844

Summary: Remove uses of wantarray in Koha::Objects
Product: Koha Reporter: Tomás Cohen Arazi (tcohen) <tomascohen>
Component: Architecture, internals, and plumbingAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: CLOSED FIXED QA Contact: Kyle M Hall (khall) <kyle>
Severity: enhancement    
Priority: P5 - low CC: dcook, fridolin.somers, jonathan.druart, kyle, m.de.rooy, martin.renvoize, nugged, tomascohen
Version: unspecified   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=28883
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=28906
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30876
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=11889
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=32472
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.05.00
Circulation function:
Bug Depends on: 29806    
Bug Blocks: 30915, 29847, 29859, 30055, 30089, 30101, 30104, 30603, 30876    
Attachments: Bug 29844: Remove use of wantarray from Koha::Objects
Bug 29844: Fix t/db_dependent/Koha/*
Bug 29844: Remove use of wantarray from Koha::Objects
Bug 29844: Fix ->search occurrences
Bug 29844: Fix ->search occurrences
Bug 29844: Some more uncaught cases
Bug 29844: Some more uncaught cases
Bug 29844: Some more uncaught cases
Bug 29844: Fix t/db_dependent/Koha/*
Bug 29844: Remove use of wantarray from Koha::Objects
Bug 29844: Fix ->search occurrences
Bug 29844: Some more uncaught cases
Bug 29844: Fix t/db_dependent/Koha/*
Bug 29844: Remove use of wantarray from Koha::Objects
Bug 29844: Fix ->search occurrences
Bug 29844: Some more uncaught cases
Bug 29844: Fix t/db_dependent/Koha/*
Bug 29844: Fix t/db_dependent/Koha/*
Bug 29844: Remove use of wantarray from Koha::Objects
Bug 29844: Fix ->search occurrences
Bug 29844: Some more uncaught cases
Bug 29844: (QA follow-up) Fix Koha::Library::Groups->all_libraries
Bug 29844: Fix t/db_dependent/Koha/*
Bug 29844: Remove use of wantarray from Koha::Objects
Bug 29844: Fix ->search occurrences
Bug 29844: Some more uncaught cases
Bug 29844: (QA follow-up) Fix Koha::Library::Groups->all_libraries
Bug 29844: (QA follow-up) Fix Koha::Library::Groups->all_libraries
Bug 29844: Simplify Koha::Clubs->get_enrollable
Bug 29844: Simplify Koha::Clubs->get_enrollable
Bug 29844: Fix selenium/administration_tasks.t
Bug 29844: Fix opac-reserve
Bug 29844: Fix advanced editor

Description Tomás Cohen Arazi (tcohen) 2022-01-10 19:02:30 UTC
They proved problematic, specially for template usage. Devs requiring list assignment should rely on ->as_list.
Comment 1 Tomás Cohen Arazi (tcohen) 2022-01-10 20:19:59 UTC
Created attachment 129285 [details] [review]
Bug 29844: Remove use of wantarray from Koha::Objects

This patch removes the use of `wantarray` from the following methods in
the Koha::Objects class:
- search
- search_related

In both cases, the change is trivial. And the tests get the 'list
context' portion removed as well.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Caveat: we broke many things by removing the feature. Check follow-up
patches as well.
Comment 2 Tomás Cohen Arazi (tcohen) 2022-01-10 20:20:03 UTC
Created attachment 129286 [details] [review]
Bug 29844: Fix t/db_dependent/Koha/*
Comment 3 Tomás Cohen Arazi (tcohen) 2022-01-10 20:21:08 UTC
Ok, I did the easy part :-D
Team work is welcome on this one.
Comment 4 Tomás Cohen Arazi (tcohen) 2022-01-10 20:28:06 UTC
Created attachment 129287 [details] [review]
Bug 29844: Remove use of wantarray from Koha::Objects

This patch removes the use of `wantarray` from the following methods in
the Koha::Objects class:
- search
- search_related

In both cases, the change is trivial. And the tests get the 'list
context' portion removed as well.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Caveat: we broke many things by removing the feature. Check follow-up
patches as well.
Comment 5 Jonathan Druart 2022-01-11 10:18:32 UTC Comment hidden (obsolete)
Comment 6 Jonathan Druart 2022-01-11 10:51:01 UTC
Created attachment 129291 [details] [review]
Bug 29844: Fix ->search occurrences

and some more...

There are lot of inconsistencies in our ->search calls. We could
simplify some of them, but not in this patch. Here we want to prevent
regressions as much as possible and so don't add unecessary changes.
Comment 7 Jonathan Druart 2022-01-11 10:56:44 UTC
Ok so, what do we do now?
Comment 8 Marcel de Rooy 2022-01-11 12:26:15 UTC
Tomas, you flexibility is unparalleled :)
Comment 9 Tomás Cohen Arazi (tcohen) 2022-01-11 12:57:46 UTC Comment hidden (obsolete)
Comment 10 Tomás Cohen Arazi (tcohen) 2022-01-11 13:28:03 UTC
Created attachment 129293 [details] [review]
Bug 29844: Some more uncaught cases

Some more cases found using

$ git grep '\->search(' | grep -v -e '\->as_list' -e '\->get_column' \
      | grep '@'

and then manually looking at them.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 11 Tomás Cohen Arazi (tcohen) 2022-01-11 13:38:05 UTC
I'm running (again) the test suite on my computer. But we really need Frido here. This is a candidate to get pushed early so we catch any outstanding issues timely.
Comment 12 Tomás Cohen Arazi (tcohen) 2022-01-11 14:01:42 UTC
Created attachment 129295 [details] [review]
Bug 29844: Some more uncaught cases

Some more cases found using

$ git grep '\->search(' | grep -v -e '\->as_list' -e '\->get_column' \
      | grep '@'

and then manually looking at them.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 13 Fridolin Somers 2022-01-12 06:55:52 UTC
(In reply to Tomás Cohen Arazi from comment #11)
> I'm running (again) the test suite on my computer. But we really need Frido
> here. This is a candidate to get pushed early so we catch any outstanding
> issues timely.

I totally agree with this change.
I started programming with Java so I like chained calls this->that->then->other().

Looks like we have catched a lot of occurencies.

I agree to pushed early yes.
Comment 14 Jonathan Druart 2022-01-31 10:54:37 UTC
Created attachment 129996 [details] [review]
Bug 29844: Fix t/db_dependent/Koha/*

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 15 Jonathan Druart 2022-01-31 10:54:42 UTC
Created attachment 129997 [details] [review]
Bug 29844: Remove use of wantarray from Koha::Objects

This patch removes the use of `wantarray` from the following methods in
the Koha::Objects class:
- search
- search_related

In both cases, the change is trivial. And the tests get the 'list
context' portion removed as well.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Caveat: we broke many things by removing the feature. Check follow-up
patches as well.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 16 Jonathan Druart 2022-01-31 10:54:49 UTC
Created attachment 129998 [details] [review]
Bug 29844: Fix ->search occurrences

and some more...

There are lot of inconsistencies in our ->search calls. We could
simplify some of them, but not in this patch. Here we want to prevent
regressions as much as possible and so don't add unecessary changes.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 17 Jonathan Druart 2022-01-31 10:54:54 UTC
Created attachment 129999 [details] [review]
Bug 29844: Some more uncaught cases

Some more cases found using

$ git grep '\->search(' | grep -v -e '\->as_list' -e '\->get_column' \
      | grep '@'

and then manually looking at them.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 18 Tomás Cohen Arazi (tcohen) 2022-02-02 13:12:47 UTC
Created attachment 130098 [details] [review]
Bug 29844: Fix t/db_dependent/Koha/*

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 19 Tomás Cohen Arazi (tcohen) 2022-02-02 13:12:52 UTC
Created attachment 130099 [details] [review]
Bug 29844: Remove use of wantarray from Koha::Objects

This patch removes the use of `wantarray` from the following methods in
the Koha::Objects class:
- search
- search_related

In both cases, the change is trivial. And the tests get the 'list
context' portion removed as well.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Caveat: we broke many things by removing the feature. Check follow-up
patches as well.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 20 Tomás Cohen Arazi (tcohen) 2022-02-02 13:13:01 UTC
Created attachment 130100 [details] [review]
Bug 29844: Fix ->search occurrences

and some more...

There are lot of inconsistencies in our ->search calls. We could
simplify some of them, but not in this patch. Here we want to prevent
regressions as much as possible and so don't add unecessary changes.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 21 Tomás Cohen Arazi (tcohen) 2022-02-02 13:13:07 UTC
Created attachment 130101 [details] [review]
Bug 29844: Some more uncaught cases

Some more cases found using

$ git grep '\->search(' | grep -v -e '\->as_list' -e '\->get_column' \
      | grep '@'

and then manually looking at them.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 22 Martin Renvoize (ashimema) 2022-02-03 09:55:30 UTC
Looking here
Comment 23 Kyle M Hall (khall) 2022-02-03 10:38:10 UTC
Created attachment 130129 [details] [review]
Bug 29844: Fix t/db_dependent/Koha/*

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 24 Kyle M Hall (khall) 2022-02-03 11:34:30 UTC
Created attachment 130130 [details] [review]
Bug 29844: Fix t/db_dependent/Koha/*

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 25 Kyle M Hall (khall) 2022-02-03 11:34:40 UTC
Created attachment 130131 [details] [review]
Bug 29844: Remove use of wantarray from Koha::Objects

This patch removes the use of `wantarray` from the following methods in
the Koha::Objects class:
- search
- search_related

In both cases, the change is trivial. And the tests get the 'list
context' portion removed as well.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Caveat: we broke many things by removing the feature. Check follow-up
patches as well.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 26 Kyle M Hall (khall) 2022-02-03 11:34:44 UTC
Created attachment 130132 [details] [review]
Bug 29844: Fix ->search occurrences

and some more...

There are lot of inconsistencies in our ->search calls. We could
simplify some of them, but not in this patch. Here we want to prevent
regressions as much as possible and so don't add unecessary changes.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 27 Kyle M Hall (khall) 2022-02-03 11:34:49 UTC
Created attachment 130133 [details] [review]
Bug 29844: Some more uncaught cases

Some more cases found using

$ git grep '\->search(' | grep -v -e '\->as_list' -e '\->get_column' \
      | grep '@'

and then manually looking at them.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 28 Martin Renvoize (ashimema) 2022-02-03 11:53:45 UTC
oh, oh...  Did you run t/db_dependant/Koha/Libraries.t Kyle.. that's failing for me.. looks like a missing change required in Koha::Library::Groups::all_libraries.
Comment 29 Kyle M Hall (khall) 2022-02-03 11:58:12 UTC
These patches are failing some unit tests.
Comment 30 Martin Renvoize (ashimema) 2022-02-03 12:14:35 UTC
Created attachment 130134 [details] [review]
Bug 29844: (QA follow-up) Fix Koha::Library::Groups->all_libraries

I think a rebase perhaps lost a change here.. this fix gets the unit
tests passing again.
Comment 31 Martin Renvoize (ashimema) 2022-02-03 12:43:55 UTC
Created attachment 130135 [details] [review]
Bug 29844: Fix t/db_dependent/Koha/*

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 32 Martin Renvoize (ashimema) 2022-02-03 12:43:59 UTC
Created attachment 130136 [details] [review]
Bug 29844: Remove use of wantarray from Koha::Objects

This patch removes the use of `wantarray` from the following methods in
the Koha::Objects class:
- search
- search_related

In both cases, the change is trivial. And the tests get the 'list
context' portion removed as well.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Caveat: we broke many things by removing the feature. Check follow-up
patches as well.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 33 Martin Renvoize (ashimema) 2022-02-03 12:44:04 UTC
Created attachment 130137 [details] [review]
Bug 29844: Fix ->search occurrences

and some more...

There are lot of inconsistencies in our ->search calls. We could
simplify some of them, but not in this patch. Here we want to prevent
regressions as much as possible and so don't add unecessary changes.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 34 Martin Renvoize (ashimema) 2022-02-03 12:44:08 UTC
Created attachment 130138 [details] [review]
Bug 29844: Some more uncaught cases

Some more cases found using

$ git grep '\->search(' | grep -v -e '\->as_list' -e '\->get_column' \
      | grep '@'

and then manually looking at them.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 35 Martin Renvoize (ashimema) 2022-02-03 12:44:12 UTC
Created attachment 130139 [details] [review]
Bug 29844: (QA follow-up) Fix Koha::Library::Groups->all_libraries

I think a rebase perhaps lost a change here.. this fix gets the unit
tests passing again.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 36 Martin Renvoize (ashimema) 2022-02-03 13:02:05 UTC
OK,
* I ran the whole test suite - Everything now passes
* I ran the QA scripts - Everything happy
* I tried a bunch of stuff in the UI and nothing failed

I'm happy to PQA this.. no doubt there will be a little fallout with such a large change, but this is a great step towards consistency.

Go, go, go!
Comment 37 Martin Renvoize (ashimema) 2022-02-03 13:28:28 UTC
Just found an issue with patron clubs whilst I moved on to test bug 29847.. setting back to Signed off whilst Tomas takes a look for me :)
Comment 38 Tomás Cohen Arazi (tcohen) 2022-02-03 13:32:15 UTC
Created attachment 130143 [details] [review]
Bug 29844: (QA follow-up) Fix Koha::Library::Groups->all_libraries

I think a rebase perhaps lost a change here.. this fix gets the unit
tests passing again.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 39 Tomás Cohen Arazi (tcohen) 2022-02-03 13:58:33 UTC
Created attachment 130145 [details] [review]
Bug 29844: Simplify Koha::Clubs->get_enrollable

This patch removes the wantarray use in Koha::Clubs->get_enrollable and
adjusts the callers.

Also, reference to some unused params in Koha::Patron clubs-related
methods are removed as well.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 40 Martin Renvoize (ashimema) 2022-02-03 14:03:41 UTC
Created attachment 130146 [details] [review]
Bug 29844: Simplify Koha::Clubs->get_enrollable

This patch removes the wantarray use in Koha::Clubs->get_enrollable and
adjusts the callers.

Also, reference to some unused params in Koha::Patron clubs-related
methods are removed as well.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 41 Martin Renvoize (ashimema) 2022-02-03 14:04:08 UTC
Back to PQA.. I'm sure things will drop out once we're using this in earnest
Comment 42 Fridolin Somers 2022-02-10 01:36:26 UTC
Pushed to master for 22.05, thanks to everybody involved ﷐[U+1F984]﷑
Comment 43 Jonathan Druart 2022-02-11 08:17:17 UTC
Created attachment 130481 [details] [review]
Bug 29844: Fix selenium/administration_tasks.t
Comment 44 Fridolin Somers 2022-02-11 18:49:36 UTC
> Bug 29844: Fix selenium/administration_tasks.t
Pushed to master
Comment 45 Jonathan Druart 2022-02-21 11:27:57 UTC
Created attachment 130947 [details] [review]
Bug 29844: Fix opac-reserve

The method Koha::AuthorisedValues->authorised_value is not covered by tests!

Trace begun at /kohadevbox/koha/Koha/Objects.pm line 572
Koha::Objects::AUTOLOAD('Koha::AuthorisedValues=HASH(0x5598ac65a780)') called at /kohadevbox/koha/opac/opac-reserve.pl line 464
Comment 46 Fridolin Somers 2022-02-22 00:08:02 UTC
(In reply to Jonathan Druart from comment #45)
> Created attachment 130947 [details] [review] [review]
> Bug 29844: Fix opac-reserve
> 
> The method Koha::AuthorisedValues->authorised_value is not covered by tests!
> 
> Trace begun at /kohadevbox/koha/Koha/Objects.pm line 572
> Koha::Objects::AUTOLOAD('Koha::AuthorisedValues=HASH(0x5598ac65a780)')
> called at /kohadevbox/koha/opac/opac-reserve.pl line 464
This is fixed by Bug 30089
Comment 47 Jonathan Druart 2022-02-23 10:03:00 UTC
Created attachment 131032 [details] [review]
Bug 29844: Fix advanced editor

The method Koha::Libraries->branchcode is not covered by tests!
Trace begun at /kohadevbox/koha/Koha/Objects.pm line 572                                                                                                                                                             Koha::Objects::AUTOLOAD('Koha::Libraries=HASH(0x563bf134b810)') called at /kohadevbox/koha/svc/cataloguing/framework line 33
Comment 48 Fridolin Somers 2022-02-24 08:06:27 UTC
Patch 'Bug 29844: Fix advanced editor' pushed to master
Comment 49 Andrii Nugged 2022-06-01 10:08:27 UTC
one more lost item (probably aren't converted too):

recalls/recalls_to_pull.pl line 74:
             my @items = Koha::Items->search({ biblio_id => $recall->biblio_id });
Comment 50 Tomás Cohen Arazi (tcohen) 2022-06-01 11:09:09 UTC
(In reply to Andrew Nugged from comment #49)
> one more lost item (probably aren't converted too):
> 
> recalls/recalls_to_pull.pl line 74:
>              my @items = Koha::Items->search({ biblio_id =>
> $recall->biblio_id });

Thanks.
Comment 51 Andrii Nugged 2022-06-04 00:08:41 UTC Comment hidden (mistake, obsolete)
Comment 52 Andrii Nugged 2022-06-04 00:13:39 UTC Comment hidden (obsolete)
Comment 53 Marcel de Rooy 2022-12-15 10:48:09 UTC
If you like researching code, please have a look at Bug 32472 - [21.11 CRASH] The method Koha::Item->count is not covered by tests. Strongly related to not having this patch set in 21.11.
Comment 54 Jonathan Druart 2023-09-18 17:09:24 UTC
*** Bug 18559 has been marked as a duplicate of this bug. ***