https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24965 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #101561|0 |1 is obsolete| | --- Comment #4 from David Nind <david@davidnind.com> --- Created attachment 102155 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=102155&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@theke.io> Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.