Skip to content

Commit 7d23660

Browse files
Make Links optional (#162)
Links field turned out to be missing when getting a request for ODL loan notifications. Make it optional for now even though it should be a required field.
1 parent a61dc8e commit 7d23660

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

api/controller/odl_notification.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def notify_deprecated(self, loan_id: int) -> Response:
6262
def notify(
6363
self, patron_identifier: str | None, license_identifier: str | None
6464
) -> Response:
65+
self.log.info(
66+
f"Loan notification received [patron: {patron_identifier}] [license: {license_identifier}]"
67+
)
6568
loan = self._get_loan(patron_identifier, license_identifier)
6669
return self._process_notification(loan)
6770

api/lcp/status.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class LoanStatus(BaseModel):
132132
status: Status
133133
message: str | None = None
134134
updated: Updated | None = None
135-
links: LinkCollection
135+
links: LinkCollection | None = None
136136
potential_rights: PotentialRights = Field(default_factory=PotentialRights)
137137
events: list[Event] | None = Field(default_factory=list)
138138

api/odl.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ def _checkin(self, loan: Loan) -> None:
349349
self.update_licensepool_and_hold_queue(loan.license_pool)
350350
return
351351

352+
assert loan_status.links # To satisfy mypy
352353
return_link = loan_status.links.get(
353354
rel="return", content_type=LoanStatus.content_type()
354355
)
@@ -486,6 +487,7 @@ def _checkout(
486487
)
487488
raise CannotLoan()
488489

490+
assert loan_status.links # To satisfy mypy
489491
# We save the link to the loan status document in the loan's external_identifier field, so
490492
# we are able to retrieve it later.
491493
loan_status_document_link: Link | None = loan_status.links.get(
@@ -639,6 +641,7 @@ def _license_fulfill(
639641

640642
drm_scheme = delivery_mechanism.delivery_mechanism.drm_scheme
641643
fulfill_cls: Callable[[str, str | None], UrlFulfillment]
644+
assert loan_status.links # To satisfy mypy
642645
if drm_scheme == DeliveryMechanism.NO_DRM:
643646
# If we have no DRM, we can just redirect to the content link and let the patron download the book.
644647
fulfill_link = loan_status.links.get(

0 commit comments

Comments
 (0)