Skip to content

Return 503 from portadmin commit_configuration#3801

Merged
lunkwill42 merged 3 commits into5.17.xfrom
bugfix/empty-portadmin-500-errors
Feb 27, 2026
Merged

Return 503 from portadmin commit_configuration#3801
lunkwill42 merged 3 commits into5.17.xfrom
bugfix/empty-portadmin-500-errors

Conversation

@lunkwill42
Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 commented Feb 25, 2026

Scope and purpose

PortAdmin's commit_configuration endpoint returned 500 for expected operational errors (unreachable device, unsupported commit, missing management handler). This would trigger unnecessary Django admin error emails with empty tracebacks that misrepresented the nature of the problem.

This PR changes those error paths to return 503 with descriptive messages, and adds a Suppress503 logging filter so that 503 responses don't generate admin emails.

This pull request

  • adds/changes/removes a dependency
  • changes the database
  • changes the API

Contributor Checklist

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff, easiest by using pre-commit
  • Wrote the commit message so that the first line continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • Based this pull request on the correct upstream branch: For a patch/bugfix affecting the latest stable version, it should be based on that version's branch (<major>.<minor>.x). For a new feature or other additions, it should be based on master.
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)
  • If this results in changes in the UI: Added screenshots of the before and after

How to observe

Trigger the commit endpoint for a device that is unreachable or doesn't support config commits. Previously this returned an HTTP 500 with an empty body; now it returns 503 with a message like Error committing configuration on <netbox>: <reason>. The Django mail_admins handler will no longer send emails for these 503 responses.

NAV/PortAdmin is changing to return 503 for expected operational errors
like unreachable devices.  These are already logged by NAV's own
loggers, so the Django `mail_admins` handler emails are redundant noise.

The `Suppress503` filter is wired into the default `mail_admins`
logging handler so that records with `status_code=503` are silently
dropped.
Errors in `commit_configuration` — unreachable device, unsupported
commit, missing handler — are expected operational failures, not
application bugs.  Returning 500 triggered unnecessary admin error
emails (with zero Traceback information) and misrepresented the nature
of the problem.

All error paths now return 503 with a descriptive message body.
@lunkwill42 lunkwill42 self-assigned this Feb 25, 2026
@sonarqubecloud
Copy link
Copy Markdown

@lunkwill42 lunkwill42 changed the title Return 503 from portadmin commit_configuration Return 503 from portadmin commit_configuration Feb 25, 2026
@lunkwill42 lunkwill42 requested a review from a team February 25, 2026 09:50
@github-actions
Copy link
Copy Markdown

Test results

    20 files      20 suites   24m 50s ⏱️
 2 877 tests  2 877 ✅ 0 💤 0 ❌
16 434 runs  16 434 ✅ 0 💤 0 ❌

Results for commit cd31491.

@lunkwill42 lunkwill42 marked this pull request as ready for review February 25, 2026 14:38
Copy link
Copy Markdown
Contributor

@Simrayz Simrayz left a comment

Choose a reason for hiding this comment

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

I think it looks great!

Excited People LGTM

Small nit: Some weird newlines in the changelog fragment and Suppress403 docstring, e.g.

  managed
devices

@lunkwill42 lunkwill42 merged commit 6f1b5c5 into 5.17.x Feb 27, 2026
17 checks passed
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.42%. Comparing base (31b94d8) to head (cd31491).
⚠️ Report is 6 commits behind head on 5.17.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           5.17.x    #3801      +/-   ##
==========================================
+ Coverage   63.37%   63.42%   +0.05%     
==========================================
  Files         619      619              
  Lines       45871    45881      +10     
  Branches       43       43              
==========================================
+ Hits        29071    29101      +30     
+ Misses      16790    16770      -20     
  Partials       10       10              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lunkwill42 lunkwill42 deleted the bugfix/empty-portadmin-500-errors branch February 27, 2026 07:00
@lunkwill42
Copy link
Copy Markdown
Member Author

Small nit: Some weird newlines in the changelog fragment and Suppress403 docstring, e.g.

  managed
devices

That's weird, I can't see anything weird about them 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants