openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Deleting check-in event errors if just added

Open akramcodez opened this issue 7 months ago • 7 comments

Problem

When removing the “Already Read” date from a book, the frontend sends a DELETE request to an incorrect endpoint:

DELETE /check-ins/

This results in a 404 Not Found, and the deletion action fails.

Reproducing the bug

  1. Go to My Books → Currently Reading / Already Read
  2. Open any book with a recorded “Already Read” date
  3. WITHOUT REFRESHING THE PAGE, Try to remove or update the read date
  4. Open DevTools → Network tab
  5. Observe the request:
Image

akramcodez avatar Apr 20 '26 14:04 akramcodez

Thank you @akramcodez for submitting this issue!

⚠️ Contributors, this issue will be ready to work on once:

  • [ ] Triage — maintainers will add Priority: * and Lead: @* to replace Needs: Triage and Needs: Lead

Context

Root cause traced to openlibrary/plugins/openlibrary/js/my-books/MyBooksDropper/CheckInComponents.js.

The submit-check-in event handler (~line 151) calls postCheckIn() and checks resp.ok, but never parses the response body. The FastAPI endpoint (openlibrary/fastapi/checkins.py:90) returns {status: "ok", id: <event_id>} on success, but this id is never passed to checkInForm.setEventId(). As a result, the form's hidden event_id input remains empty after a fresh check-in creation.

The DELETE handler (CheckInComponents.js:246) constructs /check-ins/${eventId} — when eventId is "", the URL becomes /check-ins/, reproducing the reported 404.

This is distinct from the bug fixed in PR #12394 (merged, closes #12391), which added a .json route alias for the POST endpoint. The same reporter (@akramcodez) flagged this eventId retention issue in a comment on #12391, but it was not included in that PR's changes — only openlibrary/fastapi/checkins.py was modified (+1 line).

The fix is isolated: update the submit-check-in handler to parse the JSON response and call this.checkInForm.setEventId(String(data.id)). Once triaged, this may qualify as a Good First Issue — single-file JS change, clear acceptance criteria, no deep codebase knowledge required.


Issue Assessment

Open questions

  • Is the 404 also reproducible on page reload with a pre-existing read date (i.e., is there a separate path where event_id isn't passed from the server), or only after creating a check-in in the same browser session without reloading?

Action items

  • [ ] In CheckInComponents.js, update the submit-check-in handler to parse the POST response (resp.json()) and call this.checkInForm.setEventId(String(data.id)) with the returned event ID before calling updateDateAndShowDisplay
  • [ ] Add a regression test (JS or integration) verifying that DELETE succeeds immediately after a fresh check-in POST without a page reload
Full triage checklist (maintainers / Pam)
  • [ ] Triage — correct labels applied or removed: Needs: Breakdown, Needs: Investigation, Needs: Design, Needs: Staff Decision, Needs: Staff / Admin, Good First Issue, Blocked, Blocker
  • [x] Problem / opportunity — problem is clear, audience identified, actionable
  • [x] Scope — issue is well-scoped; single-file JS fix
  • [x] Justification — deletion of read dates is broken for check-ins created in the same session
  • [ ] Success & testing criteria — no explicit test plan; a regression test is needed
  • [x] Proposal & breakdown — fix location identified (CheckInComponents.js submit-check-in handler); Needs: Breakdown removed
  • [x] If bug: environment & repro steps — repro steps and network trace screenshot provided
  • [ ] Risks, concerns, open questions — whether this also affects pre-existing read dates (separate server-side path) is unconfirmed
  • [x] Pam context — root cause confirmed in CheckInComponents.js; related fix in PR #12394 verified not to cover this code path; no duplicate issue found
  • [x] References — screenshot and network trace in issue body

[!NOTE] This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting.

mekarpeles avatar Apr 20 '26 14:04 mekarpeles

If this is a real bug, I’d like to work on it.

akramcodez avatar Apr 20 '26 15:04 akramcodez

This could have been an artifact of attempting to migrate this endpoint to FastAPI (and we've temporarily put it back to webpy so it should presumably work)?

mekarpeles avatar Apr 20 '26 19:04 mekarpeles

I switched the haproxy redirect back to webpy while this is a problem

cdrini avatar Apr 27 '26 17:04 cdrini

Actually that didn't help... Looking at it further it seems like the bug only presents when you do it on the same page. If you reload the page, then you can delete without issue. Updated reproduction steps.

cdrini avatar Apr 27 '26 17:04 cdrini

Hi @RayBB and @cdrini! I'd like to work on this issue.

My understanding of the bug: When a check-in event is added and then deleted on the same page (without refreshing), the DELETE request is sent to /check-ins/ with no ID, resulting in a 404. This happens because the submit-check-in event handler in CheckInComponents.js calls postCheckIn() but never parses the response body to extract the returned id — so the newly created event's ID is never stored for subsequent deletion.

Proposed fix: Parse the JSON response from postCheckIn() to capture the returned id, then use it when constructing the DELETE request URL.

Could I be assigned to this issue? Thank you!

joannajiang711 avatar Jun 08 '26 21:06 joannajiang711

@joannajiang711 you're assigned. Good luck.

When you open your PR please include a video showing this working locally.

RayBB avatar Jun 08 '26 21:06 RayBB