Skip to content

feat: use the variant as the exposure event value#222

Merged
gagantrivedi merged 2 commits into
mainfrom
feat/multivariate-variant-exposure
Jun 9, 2026
Merged

feat: use the variant as the exposure event value#222
gagantrivedi merged 2 commits into
mainfrom
feat/multivariate-variant-exposure

Conversation

@gagantrivedi

@gagantrivedi gagantrivedi commented Jun 9, 2026

Copy link
Copy Markdown
Member

When get_experiment_flag records a $flag_exposure event, the event value is now the selected variant when present (the variant's key, or "control"), falling back to the flag value for standard flags — making the exposure value the experiment cohort identifier. Reuses the existing value field; no change to the event shape.

@gagantrivedi gagantrivedi requested a review from a team as a code owner June 9, 2026 09:01
@gagantrivedi gagantrivedi requested review from khvn26 and removed request for a team June 9, 2026 09: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 updates get_experiment_flag to use the flag's variant as the exposure value for multivariate experiments, falling back to the standard flag value if no variant is present. It also changes the type check to ensure the flag is an instance of Flag before tracking exposure. Unit tests have been added to verify this behavior. The reviewer recommends wrapping the test logic in try...finally blocks to stop the background event processor thread and prevent resource leaks.

Comment thread tests/test_flagsmith.py
Comment thread tests/test_flagsmith.py
@gagantrivedi gagantrivedi marked this pull request as draft June 9, 2026 09:04
@gagantrivedi gagantrivedi force-pushed the feat/multivariate-variant-exposure branch from cbc3cb4 to 5d1b91e Compare June 9, 2026 09:15
@gagantrivedi gagantrivedi force-pushed the feat/multivariate-variant branch from e50ada6 to f15af26 Compare June 9, 2026 09:20
@gagantrivedi gagantrivedi force-pushed the feat/multivariate-variant-exposure branch 2 times, most recently from ddb2ac4 to 237dfa2 Compare June 9, 2026 09:36
Base automatically changed from feat/multivariate-variant to main June 9, 2026 10:05
@gagantrivedi gagantrivedi force-pushed the feat/multivariate-variant-exposure branch from 4e2ea59 to 72de3f7 Compare June 9, 2026 10:19
When `get_experiment_flag` records a `$flag_exposure` event, send the
selected variant as the event value when present (the variant's key, or
"control" for the control bucket), falling back to the flag value for
standard flags. This identifies the experiment cohort without changing
the event shape.
Flagsmith(...) can start polling, streaming and event-processor background
threads. Track every instance created during a test and stop its threads
on teardown so they don't leak across the suite — previously a leaked
polling thread could call a class-level-patched update_environment in a
later test. Replaces the scattered per-test try/finally cleanup.
@gagantrivedi gagantrivedi force-pushed the feat/multivariate-variant-exposure branch from 72de3f7 to bb278dc Compare June 9, 2026 10:28
@gagantrivedi gagantrivedi marked this pull request as ready for review June 9, 2026 10:28
@gagantrivedi gagantrivedi requested review from Zaimwa9 and removed request for khvn26 June 9, 2026 10:29

@Zaimwa9 Zaimwa9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@gagantrivedi gagantrivedi merged commit 1438708 into main Jun 9, 2026
7 checks passed
@gagantrivedi gagantrivedi deleted the feat/multivariate-variant-exposure branch June 9, 2026 11:12
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.

3 participants