Skip to content

feat: add identity_feature_state to project features endpoint#7451

Open
SahilJat wants to merge 2 commits intoFlagsmith:mainfrom
SahilJat:feature/identity-feature-state-endpoint
Open

feat: add identity_feature_state to project features endpoint#7451
SahilJat wants to merge 2 commits intoFlagsmith:mainfrom
SahilJat:feature/identity-feature-state-endpoint

Conversation

@SahilJat
Copy link
Copy Markdown
Contributor

@SahilJat SahilJat commented May 7, 2026

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #7095

This PR optimizes how identity overrides are fetched on the Identity Page by eliminating chained API calls.

Backend:

  • Updated FeatureViewSet.get_queryset in api/features/views.py to accept an identity query parameter. When provided (and the project is not Edge/DynamoDB-enabled), it fetches the resolved identity feature states using identity.get_all_feature_states() and stores them on the view instance.
  • Updated FeatureViewSet.get_serializer_context to inject identity_feature_states into the serializer context.
  • Updated CreateFeatureSerializer in api/features/serializers.py to include a new identity_feature_state field via SerializerMethodField, which reads from the injected context.

Frontend:

  • Added identity_feature_state to the ProjectFlag type in frontend/common/types/responses.ts.
  • Added identityStates to the featureList response type in Res.
  • Updated getFeatureList in frontend/common/services/useProjectFlag.ts to pass the identity parameter to the API and extract identityStates from the transformResponse.
  • Refactored frontend/web/components/pages/IdentityPage.tsx to remove the chained getActualFlags() call (which previously hit /environments/.../identities/.../all/), the actualFlags state, and associated dead Redux code. The component now reads identity_feature_state directly from useGetFeatureListQuery.

How did you test this code?

Automated tests:

  • Added integration tests in api/tests/integration/features/test_identity_feature_states.py covering:

    • Identity with an override returns correct identity_feature_state (enabled + value)
    • No identity param → identity_feature_state is None (backward compatibility)
    • Invalid/non-existent identity ID → identity_feature_state is None (graceful handling)
    • Edge (DynamoDB) project → identity_feature_state is None (no Postgres crash)
    • Identity from a different environment → identity_feature_state is None
    • Identity exists but has no override → identity_feature_state is None
  • Added unit tests in api/tests/unit/features/test_unit_identity_feature_states.py covering:

    • Serializer returns identity state from context when present
    • Serializer returns None when context has empty identity states
    • Serializer returns None when identity_feature_states key is missing from context

Manual testing steps:

  1. Start the Flagsmith backend and frontend locally.
  2. Navigate to a project → environment → Identities page.
  3. Open an identity that has at least one feature override.
  4. Verify the feature list loads correctly and overrides are displayed.
  5. Open the browser network tab — confirm only one call is made to /projects/{id}/features/?environment=X&identity=Y and the old /identities/.../all/ call is gone.
  6. Verify features without identity overrides show environment defaults correctly.

@SahilJat SahilJat requested review from a team as code owners May 7, 2026 10:09
@SahilJat SahilJat requested review from Zaimwa9 and talissoncosta and removed request for a team May 7, 2026 10:09
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

@SahilJat 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 front-end Issue related to the React Front End Dashboard api Issue related to the REST API labels May 7, 2026
@SahilJat SahilJat force-pushed the feature/identity-feature-state-endpoint branch from 47374da to 255b33e Compare May 7, 2026 10:20
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 front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return identity_feature_state in the /projects/{project_id}/features?identity=id endpoint

1 participant