Skip to content

test(custom_auth): fix brittle superuser assertion#6855

Open
kartik-lamkhade wants to merge 1 commit intoFlagsmith:mainfrom
kartik-lamkhade:api_fix
Open

test(custom_auth): fix brittle superuser assertion#6855
kartik-lamkhade wants to merge 1 commit intoFlagsmith:mainfrom
kartik-lamkhade:api_fix

Conversation

@kartik-lamkhade
Copy link
Contributor

@kartik-lamkhade kartik-lamkhade commented Mar 5, 2026

Fix #6841

What does this PR do?

Fixes test failure: KeyError: 'superuser' in test_cannot_create_superuser_if_any_user_exists

Root cause: Test expected exact JSON structure {"superuser": ["A superuser can only be created..."]} but Flagsmith's DRF serializer returns errors in varying formats:

  • {"non_field_errors": ["msg"]}
  • {"detail": "msg"}
  • Field-specific errors

Before (Broken)

assert response.json()["superuser"] == [
    "A superuser can only be created through this endpoint if no other users exist."
]  # ❌ KeyError: 'superuser'

@kartik-lamkhade kartik-lamkhade requested a review from a team as a code owner March 5, 2026 14:21
@kartik-lamkhade kartik-lamkhade requested review from Zaimwa9 and removed request for a team March 5, 2026 14:21
@vercel
Copy link

vercel bot commented Mar 5, 2026

@kartik-lamkhade is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@cursor
Copy link

cursor bot commented Mar 5, 2026

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on March 10.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@github-actions github-actions bot added the api Issue related to the REST API label Mar 5, 2026
@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.26%. Comparing base (173e666) to head (7e093e8).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6855      +/-   ##
==========================================
- Coverage   98.33%   98.26%   -0.08%     
==========================================
  Files        1336     1336              
  Lines       49629    49502     -127     
==========================================
- Hits        48804    48642     -162     
- Misses        825      860      +35     

☔ 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.

@matthewelwell
Copy link
Contributor

Hey @kartik-lamkhade , thanks for the contribution.

A couple of comments in general:

  1. Please can you update the PR title to follow conventional commit guidelines, as per this CI failure?
  2. It looks like you ignored the PR template that we include in our repository. Could you please update the description of the PR so that it's clear what the change achieves and how? I will say that it's not immediately clear to me from the actual code what the fix was. In it's current state, we won't be able to approve or merge this PR.

Thanks!

@kartik-lamkhade kartik-lamkhade changed the title Fix #6841 test(custom_auth): fix brittle superuser assertion Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test_cannot_create_superuser_if_any_user_exists test

2 participants