fix(auth): default HTTP_USER_AGENT to empty string in save_user_data - #9700
fix(auth): default HTTP_USER_AGENT to empty string in save_user_data#9700jadhavgaurav wants to merge 1 commit into
Conversation
save_user_data() read HTTP_USER_AGENT with no default, so a request with no User-Agent header (e.g. Rust's reqwest sends none by default) stored None into the non-nullable last_login_uagent column. Django raised an IntegrityError, which is not an AuthenticationException, so it wasn't caught by the sign-in view and surfaced as an unhandled HTTP 500 even with correct credentials. The sibling login path (authentication/utils/login.py) already defaults this header to "" - this brings save_user_data() in line with that existing pattern. Fixes makeplane#9672. Co-authored-by: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe sign-in authentication adapter now stores an empty string when the User-Agent header is absent. A regression test verifies that sign-in succeeds and persists the expected value. ChangesSign-in User-Agent handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change allows valid sign-ins without a User-Agent header to complete successfully while preserving existing authentication behavior. No actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description provides the root cause, fix, regression test, validation results, linked issue reference, and unrelated test failure details. It does not reproduce every template heading or mark the Bug fix checkbox, but the required information is present.
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
Fixes #9672.
POST /auth/sign-in/(email/password) returns an unhandledHTTP 500 when the request has no
User-Agentheader, after credentialsare verified successfully. Any programmatic client that omits the header
(for example Rust's
reqwest, which sends noUser-Agentby default)cannot sign in even with correct credentials.
Root cause:
Adapter.save_user_data()inapps/api/plane/authentication/adapter/base.pyreads the header with nodefault:
When the header is absent this returns
None.last_login_uagentismodels.TextField(blank=True)-blank=Truebut notnull=True, so thecolumn is
NOT NULL. SavingNoneraises anIntegrityError, which isnot an
AuthenticationException, so it isn't caught by the sign-in view'serror handling and Django returns a generic 500 instead of completing the
sign-in.
The sibling login code path already handles this correctly, which is the
inconsistency this PR resolves:
Fix
One-line change, defaulting the header to
""insave_user_data()tomatch the existing pattern in
login.py:Tests
Added
test_user_login_without_user_agent_headertoTestSignInEndpointin
apps/api/plane/tests/contract/app/test_authentication.py. It signs inwith a plain
Client()(noUser-Agentheader, unlike the module'sdjango_clientfixture which always sets one), and asserts a 302 redirect(successful sign-in) instead of a 500, plus that
last_login_uagentissaved as
"".Verified the test fails against the pre-fix code: reverted the one-line
fix locally and reran the new test, which failed with exactly the
reported error -
django.db.utils.IntegrityError: null value in column "last_login_uagent" of relation "users" violates not-null constraint- reproducing the bugend-to-end. Re-applied the fix and the test passes.
Ran the full
TestSignInEndpointclass (7 tests) and the fulltest_authentication.pyfile locally against Postgres + Redis:TestSignInEndpointtests pass, including the new regression test.TestMagicLinkGenerate/TestMagicSignIn/TestMagicSignUp/ verify-attempt classes, all withSMTP_NOT_CONFIGURED(error code 5025) - this local environment has noSMTP configured. Confirmed these are unrelated to this change and
pre-existing on
previewbefore this diff (same failures reproduce withthe fix fully reverted).
ruff checkclean on both changed files.ruff format --checkon both files flags only pre-existing, unrelatedformatting drift elsewhere in each file (confirmed identical against
previewbefore this change) - none of it touches the lines this PRchanges.
AI assistance disclosure
This fix was implemented with Claude Code assistance (code, tests, and PR
description), reviewed and verified locally before submission, per this
repo's own convention of
Co-authored-by: Claude <noreply@anthropic.com>trailers on AI-assisted commits.
Summary by CodeRabbit