Skip to content

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

Open
mangodxd wants to merge 2 commits into
Flagsmith:mainfrom
mangodxd:fix/null-environment-validation
Open

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

Conversation

@mangodxd

@mangodxd mangodxd commented Jul 7, 2026

Copy link
Copy Markdown

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

1 participant