openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Setting yearly reading goal fails silently when goal is too large

Open jimchamp opened this issue 1 year ago • 2 comments

Problem

When a patron attempts to set a yearly reading goal that is greater than 2147483647 books, the request fails but no feedback about the failure is given to the patron.

Evidence / Screenshot

Relevant URL(s)

Goals can be set here: https://openlibrary.org/account/books``

Reproducing the bug

  1. Go to https://openlibrary.org/account/books
  2. Click the "Set 2024 reading goal" affordance
  3. Set an overly ambitious goal
  • Expected behavior: Your goal is set and the modal containing the reading goal form is closed.
  • Actual behavior: Your goal is not set. The modal remains open. You're tempted to click "Submit" again, but it will do nothing if clicked.

Context

  • Browser (Chrome, Safari, Firefox, etc): Any
  • OS (Windows, Mac, etc): Any
  • Logged in (Y/N): Y
  • Environment (prod, dev, local): prod

Notes from this Issue's Lead

Proposal & constraints

Setting a max value of 2147483647 on the reading goal input element is a quick and acceptable solution. An ambitious contributor could also update the /reading-goal POST handler to validate the goal immediately, and return an appropriate status code if the goal is out of range.

Related files

Template for reading goal form: https://github.com/internetarchive/openlibrary/blob/master/openlibrary/templates/check_ins/reading_goal_form.html

POST handler for reading log goal form: https://github.com/internetarchive/openlibrary/blob/708a80a3402a65891441faf9ab548aff515e4e0e/openlibrary/plugins/upstream/checkins.py#L199-L232

Stakeholders

jimchamp avatar May 10 '24 20:05 jimchamp

Hi there @jimchamp! Can I work on this issue?

Spedi avatar May 12 '24 07:05 Spedi

@Spedi, you are assigned.

jimchamp avatar May 13 '24 16:05 jimchamp

Hi @jimchamp! I worked on the issue, but I can't test it because once I try to access the Account page on the dev website I get this error: Screenshot from 2024-05-23 13-47-08

Should I push the changes anyway? Do you have any suggestions on how I can see if the code works? The changes I made are 2:

  • Added a max="2147483647" attribute to the input class on the HTML file
  • Added this piece of code to the Python file: if goal > 2147483647: raise web.badrequest( message='Reading goal cannot exceed 2147483647 books' )

Spedi avatar May 23 '24 11:05 Spedi