[Koha-bugs] [Bug 24965] Koha::Object->to_api should handle undef counts
bugzilla-daemon at bugs.koha-community.org
bugzilla-daemon at bugs.koha-community.org
Tue Mar 24 14:04:30 CET 2020
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24965
--- Comment #2 from Tomás Cohen Arazi <tomascohen at gmail.com> ---
Created attachment 101561
-->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=101561&action=edit
Bug 24965: Make Koha::Object->to_api handle undef counts
In some cases where we write a class method that is not directly tied to
a DBIC relationship (maybe it should) we are following the following
pattern:
my $related_object = Koha::RelatedObjects->find($params,$attributes);
return unless $related_object;
return $related_object->some_iterator_on_other_class;
While this is not highly consistent (design-wise, because it would be
great if we could return an empty iterator instead of undef) we use this
broadly and consistently.
The to_api method +count handling is not failsafe to those undef cases.
And we should make it return 0 instead of trying to get ->count on
undefined objects.
This patch makes to_api fallback to 0 when it is requested to embed a
count.
To test:
1. Apply the regression test patch
2. Run:
$ kshell
k$ prove t/db_dependent/Koha/Object.t
=> FAIL: Test fails with an error about ->count on undefined variable.
3. Apply this patch
4. Repeat 2
=> SUCCESS: The patch adds the simple fallback to 0 on counts
5. Sign off :-D
Signed-off-by: Tomas Cohen Arazi <tomascohen at theke.io>
--
You are receiving this mail because:
You are watching all bug changes.
More information about the Koha-bugs
mailing list