Skip to content

feat: upgrade flagsmith-flag-engine to v10#6653

Open
gagantrivedi wants to merge 8 commits intomainfrom
feature/engine-v10-compatibility
Open

feat: upgrade flagsmith-flag-engine to v10#6653
gagantrivedi wants to merge 8 commits intomainfrom
feature/engine-v10-compatibility

Conversation

@gagantrivedi
Copy link
Member

Thanks for submitting a PR! Please check the boxes below:

  • 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

Contributes to #5991

Upgrade flagsmith-flag-engine from fix/missing-export branch to ^10.0.3 and migrate to vendored Pydantic models.

Background: Flag-engine v7+ removed all Pydantic models in favour of TypedDicts. Since the Flagsmith API relies on these Pydantic models for DynamoDB document handling and identity management, we vendor the models temporarily until the codebase can be fully migrated to the TypedDict-based API.

Key changes:

  • Bump flagsmith-flag-engine to ^10.0.3
  • Bump flagsmith SDK to ^5.1.1
  • Add pydantic-collections dependency
  • Vendor Pydantic models in util/engine_models/ from the fix/missing-export branch
  • Add context mappers in util/engine_models/context/mappers.py to bridge Pydantic models to v10 TypedDicts
  • Update imports across the codebase to use vendored models
  • Clean up unused vendored code (properties/methods not called by our code)
  • Add new tests for full coverage

How did you test this code?

  • All 2969 tests pass
  • 100% coverage on vendored code
  • Lint and typecheck pass

Temporary vendoring of Pydantic models to maintain compatibility during
migration to flag-engine v10. These models will be removed once the
codebase is fully migrated to use the TypedDict-based evaluation API.

Includes:
- Identity, Trait, and Feature state models
- Segment models with rule evaluation
- Environment and Project models
- Context mappers bridging Pydantic models to v10 TypedDicts
…dels

- Bump flagsmith-flag-engine from fix/missing-export branch to ^10.0.3
- Bump flagsmith SDK from ^3.10.0 to ^5.1.1
- Add pydantic-collections dependency

Update all imports to use vendored Pydantic models from util/engine_models
instead of flag_engine (which removed Pydantic models in v7+).

Clean up unused code from vendored models:
- Remove EnvironmentAPIKeyModel.is_valid property
- Remove FeatureModel.__eq__ and __hash__ methods
- Remove OrganisationModel.unique_slug property
- Remove SegmentRuleModel.none() and matching_function

Add pragma: no cover for unreachable edge cases:
- FeatureStateModel._get_multivariate_value fallback return
- get_hashed_percentage_for_object_ids hash collision case

Add tests for full coverage:
- test_get_segment_ids_with_segment_feature_overrides
- test_map_any_value_to_trait_value
@gagantrivedi gagantrivedi requested a review from a team as a code owner February 4, 2026 10:15
@gagantrivedi gagantrivedi requested review from khvn26 and removed request for a team February 4, 2026 10:15
@vercel
Copy link

vercel bot commented Feb 4, 2026

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

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Feb 5, 2026 4:38am
flagsmith-frontend-preview Ignored Ignored Preview Feb 5, 2026 4:38am
flagsmith-frontend-staging Ignored Ignored Preview Feb 5, 2026 4:38am

Request Review

@github-actions github-actions bot added the api Issue related to the REST API label Feb 4, 2026
@github-actions github-actions bot added the feature New feature or request label Feb 4, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-6653 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-6653 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-6653 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-6653 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-6653 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6653 Finished ✅ Results

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.21%. Comparing base (9d53063) to head (4a959d1).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6653      +/-   ##
==========================================
+ Coverage   98.20%   98.21%   +0.01%     
==========================================
  Files        1298     1313      +15     
  Lines       47108    47417     +309     
==========================================
+ Hits        46262    46572     +310     
+ Misses        846      845       -1     

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

Update trait_value type ordering and remove maxLength constraint
to match the ContextValue type definition in flag-engine v10.
@gagantrivedi gagantrivedi requested a review from a team as a code owner February 4, 2026 11:46
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Feb 4, 2026
- type: integer
- maxLength: 2000
type: string
- type: number
Copy link
Member Author

@gagantrivedi gagantrivedi Feb 4, 2026

Choose a reason for hiding this comment

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

ContextValue type changed in flag-engine v10:

  Before (fix/missing-export branch):
  ContextValue = Annotated[
      Union[None, StrictBool, float, int, Annotated[str, StringConstraints(max_length=2000)]],
      BeforeValidator(map_any_value_to_trait_value),
  ]

  After (v10.0.3):
  ContextValue = Union[None, int, float, bool, str]
```
  This changes the OpenAPI schema for trait_value - different type ordering and the maxLength: 2000 constraint on strings is gone.

  ---

@khvn26
Copy link
Member

khvn26 commented Feb 4, 2026

There are still indirect changes to coverage, which is interesting to me: https://app.codecov.io/gh/Flagsmith/flagsmith/pull/6653/indirect-changes

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Feb 4, 2026
Testing hypothesis that merged coverage from private packages workflow
is affecting the codecov/project check.
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Feb 5, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@gagantrivedi gagantrivedi force-pushed the feature/engine-v10-compatibility branch from 07739da to 246aaf8 Compare February 5, 2026 04:07
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Feb 5, 2026
@gagantrivedi gagantrivedi force-pushed the feature/engine-v10-compatibility branch from 246aaf8 to 07739da Compare February 5, 2026 04:31
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Feb 5, 2026
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Feb 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 feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants