Setting yearly reading goal fails silently when goal is too large
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
- Go to https://openlibrary.org/account/books
- Click the "Set 2024 reading goal" affordance
- 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
Hi there @jimchamp! Can I work on this issue?
@Spedi, you are assigned.
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:
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' )