Skip to content

fix(schemas): preserve multivariate option key in DynamoDB document#242

Merged
gagantrivedi merged 1 commit into
mainfrom
fix/multivariate-option-key-in-dynamodb-schema
Jun 30, 2026
Merged

fix(schemas): preserve multivariate option key in DynamoDB document#242
gagantrivedi merged 1 commit into
mainfrom
fix/multivariate-option-key-in-dynamodb-schema

Conversation

@gagantrivedi

Copy link
Copy Markdown
Member

Problem

When a multivariate option is created with a key, the key is correctly threaded into the engine model (MultivariateFeatureOptionModel.key) in flagsmith core, but it never reaches the DynamoDB environment document. Documents end up like:

"multivariate_feature_option": {
  "id": 29176,
  "value": "variant_1"
}

— no key.

Root cause

The environment document is validated against EnvironmentCompressed during compression (map_environment_to_compressed_environment_documentTypeAdapter(EnvironmentCompressed).validate_python(...)). The MultivariateFeatureOption TypedDict here only declared id and value, so Pydantic silently dropped the extra key key during validation.

Fix

Add key: NotRequired[str | None] to the MultivariateFeatureOption TypedDict so it survives serialisation. Nullable + not-required keeps backward compatibility with documents written before keys existed.

Testing

  • Added a regression test asserting key is preserved through TypeAdapter(MultivariateFeatureOption).validate_python(...).
  • The originating bug is also covered by a failing test in flagsmith core (test_map_environment_to_compressed_environment_document__mv_option_with_key__key_preserved), which will pass once this is released and the dependency bumped.

The MultivariateFeatureOption TypedDict only declared id and value, so
validating the environment document against EnvironmentCompressed dropped
the variant key during DynamoDB compression. Add the key field so it
survives serialisation to the environment document.
@gagantrivedi gagantrivedi requested a review from a team as a code owner June 30, 2026 10:01
@gagantrivedi gagantrivedi requested review from emyller and removed request for a team June 30, 2026 10:01

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request adds an optional key field (NotRequired[str | None]) to the MultivariateFeatureOption TypedDict in the DynamoDB schema, representing a stable, human-readable identifier for multivariate feature variants. Additionally, an integration test has been added to verify that the key field is correctly validated and preserved. There are no review comments, so I have no feedback to provide.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.40%. Comparing base (819921a) to head (e765c57).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #242   +/-   ##
=======================================
  Coverage   97.39%   97.40%           
=======================================
  Files         104      104           
  Lines        4613     4619    +6     
=======================================
+ Hits         4493     4499    +6     
  Misses        120      120           

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

@gagantrivedi gagantrivedi merged commit cb4c786 into main Jun 30, 2026
4 checks passed
@gagantrivedi gagantrivedi deleted the fix/multivariate-option-key-in-dynamodb-schema branch June 30, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants