LaunchDarkly importer ANDs all segment rules and included users that LaunchDarkly ORs
Maintainers usually reply within 1 day
@victrvondoom is already working on this.
Since Nov 10, 2026.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Read _import_segments in api/integrations/launch_darkly/services.py and the segment depth limit in api/segments/serializers.py; compare the importer test test_process_import_request__valid_segments__creates_segment_per_environment with LaunchDarkly’s _simple_segment_match_context semantics. First check whether the evaluation engine and JSON rules path support the required deeper rule tree. Done means preserving included users, per-rule ANDs, the OR across rules, and exclusions—or reporting an import error when faithful translation is unsupported.
Written by the indexing model from the issue text.
Description
The LaunchDarkly importer merges every rule of a segment, plus its included users, into one ALL root rule. LaunchDarkly evaluates a segment differently, so imported segments match far fewer identities than the source segment.
LaunchDarkly semantics, from its own Python SDK (ldclient/impl/evaluator.py, _simple_segment_match_context):
- Context key in
included-> in the segment. - Context key in
excluded-> not in the segment. - Otherwise in the segment if any rule matches. A rule matches if all of its clauses match.
_import_segments (api/integrations/launch_darkly/services.py, around line 1100) calls _add_clauses_to_segment_rule once per LD rule and _add_users_to_segment_rule for included, all appending to the same root_rule of type ALL. Within a single LD rule, ANDing clauses is correct. Across LD rules and the included list it turns an OR into an AND.
Repro on main at 618f0fbcc, using the existing fixture tests/unit/integrations/launch_darkly/client_responses/get_segments.json, segment dynamic-list-2:
- rule 1:
p1 in [1, 2]ANDp2 semVerGreaterThan 1.0.0 - rule 2:
p3 matches foo[0-9]{0,1} - included:
foo
I ran process_import_request(import_request) (the same call the import task makes), then created identities in the imported Test environment, set traits, and called identity.get_segments():
| identity / traits | LaunchDarkly | Flagsmith segment Dynamic List 2 (Override for test) |
|---|---|---|
foo, no traits (included) |
in segment | not in segment |
p3=foo1 only (rule 2) |
in segment | not in segment |
p1=1, p2=2.0.0 only (rule 1) |
in segment | not in segment |
foo, p1=1, p2=2.0.0, p3=foo1 |
in segment | in segment |
Only an identity that satisfies both rules and is in the included list matches. The existing test test_process_import_request__valid_segments__creates_segment_per_environment asserts this structure (the rule clauses and the included-users subrule as ANY_RULE subrules under one ALL root), so it is tested output rather than a quirk of the fixture.
The excluded handling (a NONE subrule under the ALL root) is correct.
A faithful translation needs ANY( included_key, ALL(rule1 clauses), ALL(rule2 clauses), ... ) combined with NONE(excluded), which is three levels of rule nesting. The segments API limits depth with SEGMENT_RULES_MAX_DEPTH = 2 in api/segments/serializers.py. I haven't checked whether the evaluation engine and the JSON rules path from #8245 accept deeper trees. If they do, the importer could emit that structure. If not, importing multi-rule segments as-is silently narrows targeting, and the importer could at least log an import error for any segment with more than one rule or with included users plus rules, like it already does for unmappable operators.
I can send a PR for whichever direction you prefer.
- Dominant language
- Python
- Stars
- 9.9k
- Forks
- 658
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 168
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Flagsmith/flagsmith
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Flagsmith/flagsmith#9119 · 1 comment ·
Maintainers usually reply within 1 day
-
Fix Button Alignment in SDK Installation SectionPossibly taken @manueldezman claimed this 3 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Flagsmith/flagsmith#9056 · 2 comments ·
Maintainers usually reply within 1 day
-
Cloud Python warehouse snippet omits the import needed by its short-lived-job guidancePossibly taken @jcd1991 claimed this 4 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Flagsmith/flagsmith#9045 · 1 comment ·
Maintainers usually reply within 1 day
-
Expose whether an organisation is blocked for API usagePossibly taken @PiUnknown claimed this 38 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Flagsmith/flagsmith#8773 · 1 comment ·
Maintainers usually reply within 1 day
-
influx_query_manager doesn't catch ApiException, so Influx error responses 500Possibly taken @SAY-5 claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Flagsmith/flagsmith#8510 · 1 comment ·
Maintainers usually reply within 1 day
All issues in Flagsmith/flagsmith
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 73/100
-
day_or=True union silently becomes the ISC cron AND bug when a day field expands to its full range (e.g. '0 0 */1 * */2' fires only Sun/Tue/Thu/Sat)Possibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
pallets-eco/croniter#309 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
chore
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
nyjc-computing/campus-admin#105 ·
Maintainers usually reply within 1 day
-
bug enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AOSSIE-Org/Gitcord-GithubDiscordBot#248 · 1 comment ·
Maintainers usually reply within 4 days