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

Setting yearly reading goal fails silently when goal is too large #9257

Open
jimchamp opened this issue May 10, 2024 · 3 comments · May be fixed by #9367
Open

Setting yearly reading goal fails silently when goal is too large #9257

jimchamp opened this issue May 10, 2024 · 3 comments · May be fixed by #9367
Assignees
Labels
Good First Issue Easy issue. Good for newcomers. [managed] Lead: @jimchamp Issues overseen by Jim (Front-end Lead, BookNotes) [managed] Needs: Response Issues which require feedback from lead Needs: Review Assignee Issues that may have been abandoned by assignees Priority: 4 An issue, but should be worked on when no other pressing work can be done. [managed] Theme: Yearly Reading Goals Type: Bug Something isn't working. [managed]

Comments

@jimchamp
Copy link
Collaborator

jimchamp commented May 10, 2024

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:

def POST(self):
i = web.input(goal=0, year=None, is_update=None)
goal = int(i.goal)
if i.is_update:
if goal < 0:
raise web.badrequest(
message='Reading goal update must be 0 or a positive integer'
)
elif not goal or goal < 1:
raise web.badrequest(message='Reading goal must be a positive integer')
if i.is_update and not i.year:
raise web.badrequest(message='Year required to update reading goals')
user = get_current_user()
if not user:
raise web.unauthorized(message='Requires login')
username = user['key'].split('/')[-1]
current_year = i.year or datetime.now().year
if i.is_update:
if goal == 0:
# Delete goal if "0" was submitted:
YearlyReadingGoals.delete_by_username_and_year(username, i.year)
else:
# Update goal normally:
YearlyReadingGoals.update_target(username, i.year, goal)
else:
YearlyReadingGoals.create(username, current_year, goal)
return delegate.RawText(json.dumps({'status': 'ok'}))

Stakeholders

@jimchamp jimchamp added Type: Bug Something isn't working. [managed] Good First Issue Easy issue. Good for newcomers. [managed] Priority: 4 An issue, but should be worked on when no other pressing work can be done. [managed] Lead: @jimchamp Issues overseen by Jim (Front-end Lead, BookNotes) [managed] Theme: Yearly Reading Goals labels May 10, 2024
@Spedi
Copy link
Contributor

Spedi commented May 12, 2024

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

@github-actions github-actions bot added the Needs: Response Issues which require feedback from lead label May 12, 2024
@jimchamp jimchamp removed the Needs: Response Issues which require feedback from lead label May 13, 2024
@jimchamp
Copy link
Collaborator Author

@Spedi, you are assigned.

@Spedi
Copy link
Contributor

Spedi commented May 23, 2024

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' )

@github-actions github-actions bot added the Needs: Response Issues which require feedback from lead label May 24, 2024
@jimchamp jimchamp added Needs: Review Assignee Issues that may have been abandoned by assignees Type: Bug Something isn't working. [managed] Good First Issue Easy issue. Good for newcomers. [managed] Priority: 4 An issue, but should be worked on when no other pressing work can be done. [managed] Lead: @jimchamp Issues overseen by Jim (Front-end Lead, BookNotes) [managed] Needs: Response Issues which require feedback from lead Theme: Yearly Reading Goals and removed Type: Bug Something isn't working. [managed] Good First Issue Easy issue. Good for newcomers. [managed] Priority: 4 An issue, but should be worked on when no other pressing work can be done. [managed] Lead: @jimchamp Issues overseen by Jim (Front-end Lead, BookNotes) [managed] Needs: Response Issues which require feedback from lead Theme: Yearly Reading Goals labels May 28, 2024
@anrawool anrawool linked a pull request May 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Easy issue. Good for newcomers. [managed] Lead: @jimchamp Issues overseen by Jim (Front-end Lead, BookNotes) [managed] Needs: Response Issues which require feedback from lead Needs: Review Assignee Issues that may have been abandoned by assignees Priority: 4 An issue, but should be worked on when no other pressing work can be done. [managed] Theme: Yearly Reading Goals Type: Bug Something isn't working. [managed]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants