fix(2fa): GET /2fa/api/status crashed with 500 for every caller - #338
Merged
Conversation
Found live: within seconds of the previous fix (settings-page 2FA entry point) actually calling this endpoint for the first time ever, it 500'd. Root cause was in the server log, not guessed: AttributeError: type object 'TwoFactorService' has no attribute 'get_user_two_factor_status'. Did you mean: 'get_two_factor_status'? The endpoint called a method that has never existed on TwoFactorService — the real method is get_two_factor_status. Pre-existing bug (this endpoint predates this session's work); nothing in the frontend had ever called it before, so it silently rotted. Also fixed while looking at this: even with the correct method name, the endpoint read a "backup_codes_remaining" key from the service's return dict — but get_two_factor_status only ever returns "backup_codes_count". Confirmed by reading the method directly, not guessed. Would have silently always reported 0 remaining codes. tests/unit/test_two_factor_status_endpoint.py: TDD-verified against the live bug (reproduced the exact 500, then the exact wrong-count bug) before fixing either. Needed two get_db() patches, not one: get_db_session (the FastAPI dependency) for the route layer, and src.services.two_factor_service.get_db specifically (not src.database.connection.get_db) for the service layer, because two_factor_service.py imports get_db via a module-level `from ... import get_db`, which binds its own name — patching the origin module doesn't reach it. Full suite: 125 passed, 1 skipped, no regressions. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Found live: within seconds of #335 (settings-page 2FA entry point) actually calling this endpoint for the first time ever, it 500'd.
Root cause was in the server log, not guessed:
Pre-existing bug — this endpoint predates this session's work; nothing in the frontend had ever called it before, so it silently rotted.
Also fixed: even with the correct method name, the endpoint read a
backup_codes_remainingkey thatget_two_factor_statusnever returns — the real key isbackup_codes_count. Confirmed by reading the method directly. Would have silently always reported 0 remaining codes.Test plan
tests/unit/test_two_factor_status_endpoint.py— TDD-verified against the live bug (reproduced the exact 500, then the exact wrong-count bug) before fixing eitherCo-Authored-By: Claude Sonnet 5 noreply@anthropic.com