Skip to content

fix: return 400 when environment is null in featurestate update#7957

Merged
Zaimwa9 merged 2 commits into
Flagsmith:mainfrom
mangodxd:fix/null-environment-validation
Jul 13, 2026
Merged

fix: return 400 when environment is null in featurestate update#7957
Zaimwa9 merged 2 commits into
Flagsmith:mainfrom
mangodxd:fix/null-environment-validation

Conversation

@mangodxd

@mangodxd mangodxd commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a 500 crash in /api/v1/features/featurestates/{pk}/ when the environment field is null in the request payload.

Root cause: validate_environment in FeatureStateSerializerBasic calls environment.id without checking if environment is None first, causing an AttributeError: 'NoneType' object has no attribute 'id'.

Fix: Added a null check at the beginning of validate_environment that returns a 400 validation error with the message "Environment may not be null." when the environment field is null.

Changes

  • api/features/serializers.py: Added null check in validate_environment method
  • api/tests/unit/features/test_unit_features_views.py: Added regression test test_update_feature_state__null_environment__returns_400

Related

Add null check in validate_environment to prevent AttributeError crash
when a null environment is passed in the payload to
/api/v1/features/featurestates/{pk}/.

Fixes Flagsmith#6597
@mangodxd mangodxd requested a review from a team as a code owner July 7, 2026 08:48
@mangodxd mangodxd requested review from emyller and removed request for a team July 7, 2026 08:48
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

@mangodxd is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the api Issue related to the REST API label Jul 7, 2026
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.49%. Comparing base (da194ca) to head (30e4990).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7957      +/-   ##
==========================================
- Coverage   98.63%   98.49%   -0.15%     
==========================================
  Files        1497     1497              
  Lines       59189    59192       +3     
==========================================
- Hits        58383    58299      -84     
- Misses        806      893      +87     

☔ View full report in Codecov by Harness.
📢 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.

@Zaimwa9 Zaimwa9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good to me. Thanks for your first contribution!

@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Jul 13, 2026 10:00am
flagsmith-frontend-preview Ignored Ignored Preview Jul 13, 2026 10:00am
flagsmith-frontend-staging Ignored Ignored Preview Jul 13, 2026 10:00am

Request Review

@Zaimwa9 Zaimwa9 merged commit 686bb9c into Flagsmith:main Jul 13, 2026
27 checks passed
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.

500 when calling /api/v1/features/featurestates/{pk}/ with empty environment

2 participants