Retry the profile call once on transient errors, never the login
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- authentication, backend
Direzione di ricerca
Read CONTRIBUTING.md and inspect _fetch_new_client_with_csrf_token in app/pesu.py, including its _upstream_call(self._metrics, "csrf_fetch") usage and the existing login POST path. Add tests for the listed transient and non-transient cases, metrics per attempt, client closure, and exactly one login POST. Done means the CSRF fetch retries once when appropriate, the login POST never retries, and the live suite passes with the required credentials.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🔄 Updated for v5.0.0 (2026-10-08). The CSRF fetch this issue was about no longer exists: 5.0.0 signs in through PESU Academy's mobile API, which needs no CSRF token (#241). The same idea now applies to the profile call, the one request that is safe to repeat, so the issue is rewritten around it. The original proposal is in the edit history.
⚠️ PES University students only. This change sits in the login path and has to be tested end to end against PESU Academy with real PESU credentials (see "Tests that need credentials" in
CONTRIBUTING.md). Run the whole suite with your credentials in.envand paste the summary line into your PR. Every run makes real logins to PESU Academy, so run it when you need it, not in a loop.
Summary
A login with profile: true makes two calls to PESU Academy: the login, then the profile. If the connection drops on the profile call, the whole request fails with a 502 even though the credentials were fine and the call is safe to repeat. Retry the profile call only, once, on transient network errors. Never retry the login.
Background
_fetch_profileinapp/pesu.pyPOSTs the dispatcher form (PROFILE_FORM) toDISPATCHER_URLwith the access token from the login, inside_upstream_call(self._metrics, "profile_fetch"). It only reads the student's profile, so sending it twice changes nothing on PESU's side. The access token is valid for 30 minutes, far longer than a retry takes.- The login is
_login, a POST of the credentials toLOGIN_URL(operation="login"). Repeating it would make a second login for the student: another session on PESU's side and, for a wrong password, another failed attempt against their account. It must never be retried automatically. - Today a transport error on the profile call becomes
ProfileFetchError(502), and a non-200 response does too.
Proposed change
- In
_fetch_profile, retry the POST once on a transient failure:httpx2.ConnectError,httpx2.ConnectTimeout,httpx2.RemoteProtocolError, or a 502/503/504 response.- Wait a short, jittered delay first (for example a random 200–500 ms), so many requests don't all retry at the same moment.
- Don't retry a
ReadTimeout(PESU is slow, and retrying doubles the wait), any other 4xx or 5xx, PESU's error envelope (an HTTP 200 with{"status": 403, ...}), or a response that fails to parse: those aren't transient.
- Each attempt is its own
async with _upstream_call(...)block, so/metricscounts attempts truthfully. - If #185 (overall deadline) has merged, only retry when there is time left.
- Keep the retry logic in a small helper with a comment that says why only this call is retried. Future contributors will be tempted to add retries elsewhere, and the comment should stop them.
Tests
-
ConnectErrorthen success: the profile is returned, and twoprofile_fetchcalls are recorded. -
ConnectErrortwice:ProfileFetchError(502) is raised, and the client is closed. - A 503 then a 200: it succeeds.
-
ReadTimeout, a 404, an error envelope and an unparseable response are not retried. - The login POST is called exactly once even when it fails (a regression guard).
- The live suite passes.
Acceptance criteria
- One transient failure of the profile call no longer fails a login
- The login is provably never retried (there's a test)
- Every attempt appears in
upstream_requests_total{operation="profile_fetch"}
How to contribute
- Wait until you're assigned. Comment to ask for this issue, then wait for a maintainer to assign it to you before writing any code. PRs for unassigned issues are closed without review.
- Read
CONTRIBUTING.mdfirst. It covers forking, setting up withuv, and running the tests. - Branch from
devin your fork, and open the PR againstdevwith a Conventional Commit title andCloses #186in the description. - Bump the minor version in
pyproject.tomland runuv lock(CI checks this).uv run pre-commit run --all-filesmust pass, and coverage must stay at 100%. - Update the README,
app/docs/and comments in the same PR as the behaviour they describe. - Never log, print, store or echo a password or token, including in tests, PR descriptions and screenshots.
- Lingua principale
- Python
- Stelle
- 22
- Fork
- 29
- Merge medio
- 1g 3h
- PR unite (30g)
- 19
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pesu-dev/auth
-
Check the README for dead links and fix the misleading Docker Hub badgeForse di nuovo libera @knownshah l’ha presa 18 giorni fa e non c’è nessuna pull request aperta. Apertadocumentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
pesu-dev/auth#220 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug documentation enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 54/100
I maintainer di solito rispondono entro 1 giorno
-
Commit SHA should be used instead of tag git based deployForse già presa @aditeyabaral l’ha presa 12 giorni fa. Apertabug
pesu-dev/auth#236 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Private Functions in `app.py` needs to be in separate fileForse già presa @aditeyabaral l’ha presa 12 giorni fa. Apertaapi enhancement
pesu-dev/auth#235 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Gather the campus mapping and other shared values into constants modulesForse già presa @edgelordlinux l’ha presa 12 giorni fa. Apertaapi enhancement good first issue pesuacademy student profile tests and ci/cd
pesu-dev/auth#230 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pesu-dev/auth
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
EchoTools/nevr-runtime#651 ·
I maintainer di solito rispondono entro 1 giorno
-
bug frontend rt sev-3
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
noontide-co/mainbranch#1211 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[1.x Bug] run-operation --sql reports success but rolls back writes on transaction-capable adaptersApertatriage
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
dbt-labs/dbt#16784 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno