Make direct queries of ahopl ("Holds On Pull List") IDL class return distinct results

Bug #1964986 reported by Blake GH
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Evergreen
Fix Released
Medium
Unassigned
3.9
Fix Released
Medium
Unassigned

Bug Description

EG 3.7.2
PG 9.6

We found that the pull list interface will show fewer results than it should. If you ask for 5 rows, it can show you 4, and pagination is disabled. Pretty strange when you change the dropdown and ask for 10 rows and it gives you 9! Indicating to you that there are more than 4 rows, even though you wanted 5 to begin with.

The issue ended up having to do with the IDL query for ahopl. That query can return identical rows when a patron has more than one penalty. Specifically penalties that do not block CAPTURE.

I've come up with a query that should help find branches in your ILS that could* show this bug:

select aou.shortname
from
actor.org_unit aou
join action.hold_request ahr2 on (ahr2.pickup_lib=aou.id)
join
(
select ahr.id,count(*)
from
action.hold_request ahr
join actor.usr au on(au.id=ahr.usr)
join actor.usr_standing_penalty ausp on(ausp.usr=au.id and (ausp.stop_date IS NULL OR ausp.stop_date > NOW()))
LEFT JOIN config.standing_penalty csp
ON (
 csp.id = ausp.standing_penalty AND
 csp.block_list LIKE '%CAPTURE%' AND (
  (csp.org_depth IS NULL AND ahr.pickup_lib = ausp.org_unit) OR
  (csp.org_depth IS NOT NULL AND ahr.pickup_lib IN (
  SELECT id FROM actor.org_unit_descendants(ausp.org_unit, csp.org_depth))
  )
 )
)
where
ahr.capture_time IS NULL AND
ahr.cancel_time IS NULL AND
csp.id IS NULL AND
(ahr.expire_time is NULL OR ahr.expire_time > NOW()) AND
csp.id is null
group by 1
having count(*) > 1
) bug_ids
on (bug_ids.id=ahr2.id)
group by 1

If this makes any results for you:

1. Register a workstation at one of those branches.
2. Login to the staff client with that workstation
3. Run the pull list. Start with 100 rows to get an idea of the total number you would expect.
4. Change it back down to 5 rows
5. Page through until the interface stops returning rows well before you would expect it.

The solution (I think) is to tweak that IDL query such that it doesn't return duplicate rows. I've solved it locally by adding DISTINCT at the top of the query. I'll post a branch, but any other suggestions are welcome!

Revision history for this message
Blake GH (bmagic) wrote :
tags: added: circ-holds circulation
Revision history for this message
Michele Morgan (mmorgan) wrote :

I'm not able to duplicate what Blake describes. Our production system is running 3.7.2, and Blake's query returns 19 rows, which is the majority of our public libraries.

When viewing the pull list for those libraries, I am not seeing any loss of pagination functionality, and the number of rows displayed is consistent with the chosen row count.

Interestingly, when I scrape the ahopl query from the fm_IDL.xml and limit ahr.pickup_lib to one of those libraries, the database query retrieves FEWER rows than the pull list for that branch shows in the client.

Revision history for this message
Blake GH (bmagic) wrote :

This is a small tweak to the query to help get the "most likely" branches to have the issue:

select aou.shortname,count(*)
from
actor.org_unit aou
join action.hold_request ahr2 on (ahr2.pickup_lib=aou.id)
join
(
select ahr.id,count(*)
from
action.hold_request ahr
join actor.usr au on(au.id=ahr.usr)
join actor.usr_standing_penalty ausp on(ausp.usr=au.id and (ausp.stop_date IS NULL OR ausp.stop_date > NOW()))
LEFT JOIN config.standing_penalty csp
ON (
 csp.id = ausp.standing_penalty AND
 csp.block_list LIKE '%CAPTURE%' AND (
  (csp.org_depth IS NULL AND ahr.pickup_lib = ausp.org_unit) OR
  (csp.org_depth IS NOT NULL AND ahr.pickup_lib IN (
  SELECT id FROM actor.org_unit_descendants(ausp.org_unit, csp.org_depth))
  )
 )
)
where
ahr.capture_time IS NULL AND
ahr.cancel_time IS NULL AND
csp.id IS NULL AND
(ahr.expire_time is NULL OR ahr.expire_time > NOW()) AND
csp.id is null
group by 1
having count(*) > 1
) bug_ids
on (bug_ids.id=ahr2.id)
group by 1
order by 2 desc

Start testing from the first returned result.

tags: added: pullrequest
Revision history for this message
Jessica Woolford (jwoolford) wrote :

I can replicate this for a large library on our system running 3.6.5. I also saw one case for a smaller library where there were 14 rows when the number of rows was set 25 and 15 when it was set 5 rows.

Changed in evergreen:
status: New → Confirmed
Revision history for this message
Jessica Woolford (jwoolford) wrote :
Revision history for this message
Jennifer Weston (jweston) wrote :

I have tested this code and consent to signing off on it with my name, Jennifer Weston, and my email address, <email address hidden>

During Bug Squashing week on Terran's test server.
Tested with various combinations of patron home library, item owning library, and pickup library.
Tested with multiple patron non-alerting notes and alerting notes with no blocks at various depths (Everywhere, System, and Branch). All behaved as expected.

tags: added: signedoff
Changed in evergreen:
milestone: none → 3.9.1
Changed in evergreen:
milestone: 3.9.1 → 3.9.2
Changed in evergreen:
milestone: 3.9.2 → 3.10.2
importance: Undecided → Medium
Revision history for this message
Galen Charlton (gmc) wrote :

This bug report as stated is now moot on all supported versions of Evergreen, as the Angular version of the pull list does not use the ahopl IDL class, nor is there any other active code that uses that class directly. I.e., this is a bug with the AngularJS pull list.

(Also, the proposed fix is insufficient: if a hold has multiple hold notes, as is done in Concerto for staff-placed holds, the open-ils.fielder call that the AngularJS pull lists invokes does a left join on action.hold_request_note. That throws off pagination and retrieval by the grid regardless of the "DISTINCT" in ahopl.)

It is possible that there are reports still using the ahopl/"Holds On Pull List" source. However, since Clark effectively dedupes all report query output, an extra "DISTINCT" in ahopl would have no effect.

Nonetheless, I've pushed this patch, as theoretically there could be local code still out there making direct PCRUD queries against ahopl. I've taken the liberty of editing the commit message, and will also open a bug to propose a deprecation of ahopl.

summary: - Pull list can lose pagination when a patron has more than one penalty
+ Make direct queries of ahopl ("Holds On Pull List") IDL class return
+ distinct results
Changed in evergreen:
status: Confirmed → Fix Committed
Changed in evergreen:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.