Fix hold notifications falsely reporting availability for ODL titles (PP-3907)#3182
Merged
jonathangreen merged 2 commits intomainfrom Mar 31, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3182 +/- ##
=======================================
Coverage 93.27% 93.28%
=======================================
Files 496 496
Lines 45971 46004 +33
Branches 6290 6300 +10
=======================================
+ Hits 42881 42915 +34
Misses 2002 2002
+ Partials 1088 1087 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Expand the hold loop to handle all active holds, not just ready ones. Any non-expired hold now triggers early return, bypassing library filtering and borrowing-policy checks. This prevents patrons from ending up with holds on multiple pools for the same work. Hold filtering (excluding expired ready holds) and position ordering are pushed into the SQL query. The pools_with_holds tiebreaker is removed since holds are now resolved via early return. Tests are renamed from test_borrow_* to test_best_lendable_pool_*, simplified to use default_patron directly instead of Flask request context, and DRYed up with a second_pool() helper and a best_lendable_pool partial on LoanFixture.
3f1a7cc to
98fc7d1
Compare
The expired-hold test used identical metrics for both pools, making the selected pool depend on nondeterministic iteration order from the DB query. Give the pools distinct hold-queue ratios so normal selection deterministically picks the expected pool.
2 tasks
jonathangreen
added a commit
that referenced
this pull request
Mar 31, 2026
## Description Add a warning-level log when every license in a pool fails checkout in `OPDS2WithODLApi._checkout()`. This targets the scenario where the system believes copies are available but the distributor disagrees, the patron gets a "hold available" notification, but checkout fails because no licenses can actually be checked out. ## Motivation and Context Patrons are receiving "Your hold is available!" push notifications but when they open the app to borrow the book, it fails. PR #3182 fixes a known bug in `best_lendable_pool()`, but I'm not confident it covers all cases. This logging will help diagnose the root cause if the issue persists (PP-3907). ## How Has This Been Tested? - Logging-only change, exercised by existing tests - All pre-commit hooks pass ## Checklist - [x] I have updated the documentation accordingly. - [x] All new and existing tests passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix a bug in
best_lendable_pool()where hold notifications falsely reported availability for ODL titles. When a patron's hold became ready (position=0), the method ignored existing holds and selected a different pool based on availability metrics, causing checkout to fail with "no available copies."Two issues were fixed:
or-based comparison allowed a pool with 0 available copies and a short queue to beat a pool with many available copies. Replaced with holistic logic that compares availability first, then hold queue ratio normalized by owned licenses.Motivation and Context
Users were receiving "Your hold is available!" push notifications, but when they tapped to borrow the book, the checkout failed. This primarily affected titles with multiple LicensePools for the same work (from different collections), multiple licenses per LicensePool, and high circulation volume.
How Has This Been Tested?
Checklist