Skip to content

fix(2fa): GET /2fa/api/status crashed with 500 for every caller - #338

Merged
prefect421 merged 1 commit into
devfrom
fix/2fa-status-endpoint-crash
Aug 11, 2026
Merged

fix(2fa): GET /2fa/api/status crashed with 500 for every caller#338
prefect421 merged 1 commit into
devfrom
fix/2fa-status-endpoint-crash

Conversation

@prefect421

Copy link
Copy Markdown
Owner

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:

AttributeError: type object 'TwoFactorService' has no attribute 'get_user_two_factor_status'. Did you mean: '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: even with the correct method name, the endpoint read a backup_codes_remaining key that get_two_factor_status never returns — the real key is backup_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 either
  • Full suite: 125 passed, 1 skipped, no regressions

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

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>
@github-actions github-actions Bot added the Area: API Changes to API endpoints and related functionality label Aug 11, 2026
@prefect421
prefect421 merged commit 40021fa into dev Aug 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: API Changes to API endpoints and related functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant