Skip to content

Migrate account loans to FastAPI#12889

Merged
RayBB merged 14 commits into
internetarchive:masterfrom
Shikhar-395:fastapi-account-loans
Jun 17, 2026
Merged

Migrate account loans to FastAPI#12889
RayBB merged 14 commits into
internetarchive:masterfrom
Shikhar-395:fastapi-account-loans

Conversation

@Shikhar-395

@Shikhar-395 Shikhar-395 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrates the account loan and loan-history routes from legacy web.py routing to FastAPI while preserving existing My Books rendering and lending helper behavior.

Migrated endpoints:

  • GET /account/loans.json
  • GET /account/loan-history.json

Testing

  • Side-by-side checks confirmed /account/loans.json matches legacy behavior.
  • Loan-history routes match the same local dev archive.org user_borrow_history 401 behavior on both legacy and FastAPI.

Stakeholders

@RayBB

@accesslint accesslint Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 6 issues across 2 rules.

class TestAccountLoansPages:
def test_loans_page_renders_legacy_template(self, fastapi_client, mock_optional_authenticated_user):
legacy_user = FakeLegacyUser()
template = web.storage(rawtext="<main>Loans page</main>")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best Practice: Page has multiple main landmarks.

Page should have exactly one main landmark.

Details

The main landmark contains the primary content of the page. Screen readers allow users to jump directly to main content. Use a single <main> element (or role='main') to wrap the central content, excluding headers, footers, and navigation.


Best Practice: Page has multiple main landmarks.

Page should not have more than one main landmark.

Details

Only one main landmark should exist per page. The main landmark identifies the primary content area. If you have multiple content sections, use <section> with appropriate headings instead of multiple main elements.

@RayBB RayBB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start. We only want to migrate the json endpoints for this so where encoding = "json" in the get method.

Once you fix that up tag @Sanket17052006 to review/test!

@Shikhar-395

Copy link
Copy Markdown
Contributor Author

@Sanket17052006 PTAL.

@Sanket17052006 Sanket17052006 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the tests and endpoints are working as intended. LGTM!

@github-actions github-actions Bot added the Needs: Response Issues which require feedback from lead label Jun 11, 2026
@RayBB RayBB self-assigned this Jun 11, 2026
@github-project-automation github-project-automation Bot moved this from Waiting Review/Merge from Staff to Someone else is working on it in Ray's Project Jun 11, 2026
@github-project-automation github-project-automation Bot moved this to Waiting Review/Merge from Staff in Ray's Project Jun 11, 2026

@RayBB RayBB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this up on testing and it kind of worked except failing intermittently because of the shim. We never should shim threaded dicts for web.ctx for fastapi endpoints because they can hit race conditions.

As such, I removed the shim and replaced the web.ctx.site with calls to site.get().

This is working very well on testing and it's ready to merge.

Thanks for your work on this one! It was a deceptively hard one with all the code paths that this goes down.

A great next step would be to try to asyncify these two endpoints but might also be a challenging one since the IA code goes through many layers.

@RayBB RayBB merged commit 4fd3d2b into internetarchive:master Jun 17, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Someone else is working on it to Done in Ray's Project Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants