Repository navigation
fix(features): allow partial feature state updates without the environment - #9145
Open
anshuraj669 wants to merge 1 commit into
Open
anshuraj669 wants to merge 1 commit into
anshuraj669 wants to merge 1 commit into
Conversation
…nment
PATCH /api/v1/features/featurestates/{id}/ with a body such as
{"enabled": true} returned a 500 (KeyError: 'environment'), for both user
tokens and master API keys. SimpleFeatureStateViewSet does not put the
environment in the serializer context, and the serializer's validate()
read it from there when the request body omitted it. A partial update now
falls back to the feature state's own environment.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@anshuraj669 is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval skipped because this PR is from an external contributor.
Re-trigger cubic
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature. (Not required: bug fix, no behaviour change for valid requests.)Changes
Closes #9144
A partial update of a feature state that leaves out
environmentreturns a 500 instead of updating the feature state:SimpleFeatureStateViewSetdoes not put the environment in the serializer context, andvalidate()read it fromself.context["environment"]whenever the body did not include it. A PATCH that only sendsenabled(for example, a script or integration turning a flag off with a master API key) therefore always failed. Sendingenvironmentandfeaturealong was the only workaround.validate()now uses, in order: the environment in the request, the one in the serializer context, and finally the environment of the feature state being updated. Requests that already send the environment behave as before, and changing a feature state's environment is still rejected byvalidate_environment().I found this while building an integration that turns a flag off through the Admin API with a master API key.
How did you test this code?
test_partial_update_feature_state__environment_omitted__updates_feature_state. It runs with both a user token and a master API key (admin_client_new). Without the fix it fails with the sameKeyError: 'environment'; with the fix it passes and the feature state is updated.pytest tests/unit/features tests/unit/environments: 1334 passed, 5 skipped.ruff check,ruff format --checkandmypyon the changed files: clean.PATCH /api/v1/features/featurestates/{id}/with{"enabled": false}and anApi-Keyheader returned a 500 before the fix.🤖 Generated with Claude Code