LaunchDarkly importer ANDs all segment rules and included users that LaunchDarkly ORs

Aperta
#8,721 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@victrvondoom ci sta già lavorando.

Dal 10/11/2026.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api, backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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):

  1. Context key in included -> in the segment.
  2. Context key in excluded -> not in the segment.
  3. 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] AND p2 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.

Lingua principale
Python
Stelle
9.9k
Fork
658
Merge medio
1g 15h
PR unite (30g)
168

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Flagsmith/flagsmith

Tutte le issue di Flagsmith/flagsmith

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.