Koha-clms/t/Koha
Martin Renvoize 6563255743
Bug 42995: (QA follow-up) Harden nested +count FK-chain resolution
The FK-chain resolution added in the previous patch only handles ONE
level of nesting: it requires $parent_alias to be a direct relationship
of $main_source. This holds for every +count embed currently declared
in api/v1/swagger/ (all exactly one level deep, e.g.
biblio.items+count), but if that assumption is ever violated - a
deeper nested +count, a parent relation with a coderef (custom join)
condition, or no matching FK column name - the previous code silently
fell back to the pre-fix expression ($parent_alias.$fk_self), which can
reference a join alias that isn't available inside DBIC's limiting
subquery, reproducing the original 500 with no diagnostic.

This patch makes _build_count_subquery decline to build a subquery
(return undef) when the correlation can't be safely resolved, instead
of emitting SQL that may be broken. The caller already has an existing,
tested degradation path for "no DBIC relationship info" (prefetch the
association directly; to_api falls back to the Perl-level ->count call;
sorting on it is rejected with a clean 400) - unresolved nested
correlations now go through that same path rather than risking a 500.

Also:
- Extract the repeated "_resultset vs _result" result-source lookup
  into a shared _result_source() helper (was duplicated in
  dbic_merge_prefetch and _build_count_subquery).
- Document the one-level-deep limitation in _build_count_subquery's POD.
- Add a regression test pinning the 2-level-nested-+count case: it must
  fall back to a plain prefetch (no COUNT subquery) rather than error
  or emit unsafe SQL.

Test plan:
1. ktd --shell
2. prove t/Koha/REST/Plugin/Query.t t/db_dependent/Koha/Object.t \
       t/db_dependent/Koha/REST/Plugin/Objects.t \
       t/db_dependent/api/v1/acquisitions_orders.t \
       t/db_dependent/api/v1/acquisitions_vendors.t \
       t/db_dependent/api/v1/ill_requests.t \
       t/db_dependent/api/v1/tickets.t \
       t/db_dependent/api/v1/patrons.t
=> All pass, no regressions.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-07-13 15:46:18 +00:00
..
Auth Bug 42406: (QA follow-up) fix little inconsistencies and errors 2026-05-01 11:04:30 -06:00
Authority
…
Database Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
DateTime/Format Bug 38944: Manual changes 2025-03-13 17:25:04 +01:00
I18N/po/xx_XX/LC_MESSAGES
…
Installer Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Middleware Bug 39789: Add unit tests 2026-04-23 16:04:05 -06:00
Object Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Plugins Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
REST/Plugin Bug 42995: (QA follow-up) Harden nested +count FK-chain resolution 2026-07-13 15:46:18 +00:00
Result Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
SearchEngine Bug 42764: Fix spelling errors across the codebase 2026-06-03 16:09:04 +00:00
Util Bug 12757: Set float type on OpenDocument cells 2026-06-18 16:02:11 +00:00
CSV.t Bug 41619: Add Koha::CSV 2026-02-06 15:17:02 -07:00
Config.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
ContentSecurityPolicy.t Bug 38365: Remove old usage of Koha::Cache::Memory::Lite 2026-03-16 11:57:31 +01:00
Email.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Exceptions.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
I18N.t Bug 36947: Add system preference for configurable locale-based facet sorting 2025-07-11 15:26:56 -06:00
ItemType.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Manual.t Bug 40845: Remove hardcoded Koha version from t/Koha/Manual.t 2025-10-31 15:26:09 -06:00
Script.t Bug 40943: Fix t/Koha/Script.t 2025-11-07 07:43:52 -07:00
Script_cron.t Bug 40943: Fix Script_cron.t 2025-11-04 07:15:11 -07:00
Status.t Bug 41107: Add /status/version API endpoint 2026-03-23 09:33:54 +01:00
Z3950responder.t
…
sleep.pl
…
wait.pl
…