fix(sentry): don't report settings-save input validation as errors#3068
Merged
Conversation
ANTHIAS-3D ("AuthSettingsError: New passwords do not match!") is
operator input validation, not a bug — a mismatched/incorrect
password, a taken username, or a too-weak password typed into the
settings form. Both settings-save surfaces caught it under a broad
`except Exception` + `logger.exception(...)`, and Sentry's logging
integration turns that ERROR record into an event.
- catch AuthSettingsError ahead of the generic handler in both the
HTML view and the DRF v2 view; log it at warning (no traceback) so
it never reaches the logging integration, and surface the
operator-friendly message (the v2 view previously buried it under a
generic "An error occurred")
- add AuthSettingsError to the before_send drop filter as a backstop
for any other path that logs it as an error
- spell auth.py's AnyRequest as an explicit TypeAlias: the implicit
form flipped to mypy "not valid as a type" once settings.py began
importing the module
- regression tests for the before_send drop and the warning-level,
no-traceback v2 rejection
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
There was a problem hiding this comment.
Pull request overview
This PR reduces Sentry noise by treating AuthSettingsError from the settings-save flow as expected operator input validation (e.g., password mismatch, weak password, username taken) rather than a server error, while preserving operator-facing feedback and adding regression coverage.
Changes:
- Catch
AuthSettingsErrorexplicitly in both the HTML settings save view and the v2 DRF PATCH endpoint, logging at WARNING (no traceback) and returning/printing the operator-friendly message. - Add
AuthSettingsErrorto Sentry’s_sentry_before_senddrop filter as a backstop. - Add regression tests verifying the before_send drop and that the v2 endpoint logs validation failures at WARNING without
exc_infoand persists nothing.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_sentry.py | Adds coverage ensuring Sentry drops AuthSettingsError events via before_send. |
| src/anthias_server/lib/auth.py | Refines typing for AnyRequest via explicit TypeAlias to keep mypy stable when imported from settings. |
| src/anthias_server/django_project/settings.py | Drops AuthSettingsError in _sentry_before_send (lazy import) to prevent operator validation from becoming Sentry events. |
| src/anthias_server/app/views.py | Handles AuthSettingsError separately in settings_save, logs WARNING, and shows operator-friendly message. |
| src/anthias_server/api/views/v2.py | Handles AuthSettingsError separately in device settings PATCH, logs WARNING, and returns 400 with the specific message. |
| src/anthias_server/api/tests/test_v2_endpoints.py | Adds regression test asserting 400 + message, no persistence, and no ERROR/exc_info logging for password mismatch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.



Issues Fixed
Sentry ANTHIAS-3D (
AuthSettingsError: New passwords do not match!, culprit/settings/save/).Description
AuthSettingsErroris operator input validation from the settings-save flow — a mismatched or incorrect password, a username already taken, or a password that fails the strength validators. It is not a bug: the message is already shown to the operator and the next attempt self-corrects.Both settings-save surfaces (the HTML view and the DRF v2 view) caught it under a broad
except Exceptionfollowed bylogger.exception(...). Sentry's logging integration turns that ERROR-level record into an event, so an operator typo pages us.This fixes it at the source and adds a backstop:
AuthSettingsErrorahead of the generic handler in bothsettings_save(HTML) andDeviceSettingsViewV2.patch(DRF). Log it atwarning(no traceback) instead oflogger.exception— a WARNING record never becomes a Sentry event. The DRF view now also echoes the operator-friendly message instead of burying it under a generic "An error occurred while saving settings."AuthSettingsErrorto thebefore_senddrop filter as a backstop for any other code path that might log it as an error — this is the "ignore for similar things" net.auth.py'sAnyRequestas an explicitTypeAlias. The implicitAnyRequest = HttpRequest | DRFRequestform flipped to mypyVariable … is not valid as a typeoncesettings.pystarted importing the module for the filter; the explicit alias resolves the forward-ref robustly regardless of import order.before_senddrop and for the warning-level, no-traceback v2 rejection (asserts 400 + the specific message, nothing persisted, and no ERROR/exc_inforecord).This mirrors the same "expected transient/expected state, not a bug" treatment the
before_sendfilter already gives redis blips and client disconnects.Checklist
🤖 Generated with Claude Code