Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should default return type for is_loaned_out_on_ia should be False not None? #9118

Open
RayBB opened this issue Apr 19, 2024 · 4 comments · May be fixed by #9139
Open

Should default return type for is_loaned_out_on_ia should be False not None? #9118

RayBB opened this issue Apr 19, 2024 · 4 comments · May be fixed by #9139
Labels
Lead: @mekarpeles Issues overseen by Mek (Staff: Program Lead) [managed] Module: Borrowing / Lending Needs: Review This issue/PR needs to be reviewed in order to be closed or merged (see comments). [managed] Priority: 3 Issues that we can consider at our leisure. [managed] Type: Bug Something isn't working. [managed] Type: Question This issue doesn't require code. A question needs an answer. [managed]

Comments

@RayBB
Copy link
Collaborator

RayBB commented Apr 19, 2024

Problem

Evidence / Screenshot

def is_loaned_out_on_ia(identifier):
"""Returns True if the item is checked out on Internet Archive."""
url = "https://archive.org/services/borrow/%s?action=status" % identifier
try:
response = requests.get(url).json()
return response and response.get('checkedout')
except Exception: # TODO: Narrow exception scope
logger.exception("is_loaned_out_on_ia(%s)" % identifier)
return None

This code returns None.
I'm fairly certain we should not return None. Based on how it is used, it is evaluating to False. As in "false, the book isn't loaned out because there was an error". In my opinion, we should probably default to returning True instead.

I've gotten a bit stumped a few times trying to follow the code. However, at least the code path ending here with waitinglists seems like it would get an error from this logic.

$ checkedout = book.get
$ borrow_status = get_borrow_status(book.ocaid, edition=book)
$if borrow_status.has_loan or borrow_status.resource_epub == 'checkedout' or borrow_status.resource_pdf == 'checkedout':
$ klass = "has-loan"
$else:
$ klass = ""

Relevant URL(s)

Reproducing the bug

No response

Context

Found during #9117

Notes from this Issue's Lead

Proposal & constraints

Related files

Stakeholders

@RayBB RayBB added Type: Bug Something isn't working. [managed] Needs: Triage This issue needs triage. The team needs to decide who should own it, what to do, by when. [managed] Needs: Lead labels Apr 19, 2024
@mekarpeles mekarpeles changed the title Possible bug found in lending logic Should default return type for is_loaned_out_on_ia should be False not None? Apr 22, 2024
@mekarpeles mekarpeles added Module: Borrowing / Lending Type: Question This issue doesn't require code. A question needs an answer. [managed] labels Apr 22, 2024
@mekarpeles
Copy link
Member

There's an open question about what to do when a title is not borrowable at all, which is probably what None was trying to communicate. True is actually misleading in this case, because it's not the case that the item is lent out, it's the case that the title is simply not borrowable and we don't want the UI to communicate that the title is checked out.

@mekarpeles mekarpeles added Lead: @mekarpeles Issues overseen by Mek (Staff: Program Lead) [managed] Priority: 3 Issues that we can consider at our leisure. [managed] and removed Needs: Lead labels Apr 22, 2024
@RayBB
Copy link
Collaborator Author

RayBB commented Apr 22, 2024

@mekarpeles I see what you mean.

In that case I think the solution is one level up is to check if is_loaned_out_on_ia is True.
This way it when we return None is_loaned_out doesn't think it's available.

Should we make that change?

def is_loaned_out(identifier):
"""Returns True if the given identifier is loaned out.
This doesn't worry about waiting lists.
"""
# is_loaned_out_on_acs4 is to be deprecated, this logic (in PR)
# should be handled by is_loaned_out_on_ia which calls
# BorrowBooks.inc in petabox
return (
is_loaned_out_on_ol(identifier)
or is_loaned_out_on_acs4(identifier)
or is_loaned_out_on_ia(identifier)
)

@mekarpeles mekarpeles removed the Needs: Triage This issue needs triage. The team needs to decide who should own it, what to do, by when. [managed] label Apr 22, 2024
@mekarpeles
Copy link
Member

Yes I think that's reasonable

@RayBB RayBB linked a pull request Apr 23, 2024 that will close this issue
@RayBB RayBB added the Needs: Review This issue/PR needs to be reviewed in order to be closed or merged (see comments). [managed] label Apr 23, 2024
@RayBB
Copy link
Collaborator Author

RayBB commented Apr 23, 2024

@mekarpeles I made a PR for this here #9139

Though I'm not totally sure how to test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lead: @mekarpeles Issues overseen by Mek (Staff: Program Lead) [managed] Module: Borrowing / Lending Needs: Review This issue/PR needs to be reviewed in order to be closed or merged (see comments). [managed] Priority: 3 Issues that we can consider at our leisure. [managed] Type: Bug Something isn't working. [managed] Type: Question This issue doesn't require code. A question needs an answer. [managed]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants