flagsmith-sql-flag-engine 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flagsmith-sql-flag-engine
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: SQL translator for Flagsmith segment predicates.
5
5
  Author: Flagsmith
6
6
  Author-email: Flagsmith <engineering@flagsmith.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "flagsmith-sql-flag-engine"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  description = "SQL translator for Flagsmith segment predicates."
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Flagsmith", email = "engineering@flagsmith.com" }]
@@ -432,7 +432,6 @@ def translate_condition(cond: SegmentCondition, ctx: TranslateContext) -> str |
432
432
  # Engine: float() on the threshold raises → returns False.
433
433
  return "FALSE"
434
434
  threshold = float(threshold_lit)
435
- identity: dict[str, object] = ctx.evaluation_context.get("identity") or {} # type: ignore[assignment]
436
435
  kind = classification.kind
437
436
  if not prop:
438
437
  # In traditional engine implementations, this branch implies
@@ -457,13 +456,18 @@ def translate_condition(cond: SegmentCondition, ctx: TranslateContext) -> str |
457
456
  # future work and let the caller fall back to the engine.
458
457
  return None
459
458
  else:
460
- # Plain trait key, or `$.identity.traits.<X>` rewritten to
461
- # the bare key. Hash subject pulls from `i.traits:"<key>"`
462
- # per row.
463
- traits = identity.get("traits") or {}
464
- if not isinstance(traits, dict) or prop not in traits:
465
- return "FALSE"
466
- value_expr = ctx.dialect.cast_string(ctx.trait_path(prop))
459
+ # Plain trait key, or `$.identity.traits.<X>` rewritten to the
460
+ # bare key. Hash the per-row trait value from `i.traits:"<key>"`.
461
+ # A row missing the trait has no value to bucket, so it cannot
462
+ # match — mirroring the engine's `context_value is None -> False`.
463
+ trait_sql = ctx.trait_path(prop)
464
+ split = _percentage_split_expr(
465
+ ctx,
466
+ ctx.segment_key,
467
+ ctx.dialect.cast_string(trait_sql),
468
+ threshold,
469
+ )
470
+ return f"({trait_sql} IS NOT NULL AND {split})"
467
471
  return _percentage_split_expr(ctx, ctx.segment_key, value_expr, threshold)
468
472
 
469
473
  if not prop: