Skip to content

feat(flagd-core): allow computed fractional bucket variants - #484

Open
cvas22 wants to merge 1 commit into
open-feature:mainfrom
cvas22:feat/482-computed-fractional-variants
Open

cvas22 wants to merge 1 commit into
open-feature:mainfrom
cvas22:feat/482-computed-fractional-variants

Conversation

@cvas22

@cvas22 cvas22 commented Nov 20, 2026

Copy link
Copy Markdown

Closes #482

The Python fractional operator already returned whatever the variant expression evaluated to, so computed variants like {"cat": ["r", "ed"]} worked. I loosened the type hints to say so (Fraction.variant and the return type are now Any) and added tests for a computed variant, picking a bucket by weight, and a non-scalar result being passed through. This is so the upcoming resolve operator can be used as a bucket variant.

I ran tests/test_targeting.py locally on Python 3.12 and it passes, and ruff is clean.

A bucket variant can be any JSON Logic expression. The variant is already passed through untouched, so this loosens the type hints to match and adds tests for a computed variant and a non-scalar result.

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22
cvas22 requested review from a team as code owners November 20, 2026 09:15
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The fractional variant and return type declarations now use typing.Any. Tests cover computed JSON Logic bucket variants, selection by bucket weight, and pass-through of dictionary variants.

Changes: Computed fractional variants

Layer / File(s) Summary
Fractional variant types and tests
tools/openfeature-flagd-core/src/openfeature/contrib/tools/flagd/core/targeting/custom_ops.py, tools/openfeature-flagd-core/tests/test_targeting.py
The Fraction.variant field and fractional return type use typing.Any. Tests cover computed expression results selected by bucket weights and unchanged dictionary results.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Suggested reviewers: aepfli, m-olko, federicobond

Merge Risk: Minimal · up to 62bda

This change loosens type hints so fractional bucket variants can be computed expressions, and it adds tests for that. Runtime behavior is unchanged, so the risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: fractional bucket variants now accept computed (JSON Logic) expressions, as the summary and objectives describe. It is specific and follows the conventional commit fo…
Description check Passed The description states the purpose and scope. It explains that the Python fractional operator already returned evaluated variant results, that the type hints for Fraction.variant and the return type w…
Linked Issues check Passed Directly linked issue #482 has three coding requirements. (1) Computed bucket variants: Fraction.variant is typed typing.Any and _parse_fraction stores arg[0] unchanged, so an evaluated expres…
Out of Scope Changes check Passed The changes are limited to the Fraction.variant and fractional type annotations in custom_ops.py (+3/-2, per summary) and three added tests in tests/test_targeting.py (+28 lines). The type ann…
Full details: Title check

Explanation

The title states the main change: fractional bucket variants now accept computed (JSON Logic) expressions, as the summary and objectives describe. It is specific and follows the conventional commit form. The title does not mention the type-hint change or the tests, which is acceptable.

Full details: Description check

Explanation

The description states the purpose and scope. It explains that the Python fractional operator already returned evaluated variant results, that the type hints for Fraction.variant and the return type were changed to Any, and that tests were added for computed variants, weight-based selection, and non-scalar pass-through. It also gives the motivation (the upcoming resolve operator) and the local test results. It matches the changeset.

Full details: Linked Issues check

Explanation

Directly linked issue #482 has three coding requirements. (1) Computed bucket variants: Fraction.variant is typed typing.Any and _parse_fraction stores arg[0] unchanged, so an evaluated expression is returned for the selected bucket. The test test_fractional_computed_variant_expression checks {"cat": ["r", "ed"]} resolves to "red" through targeting(). (2) No type-based rejection: fractional returns typing.Any, and test_fractional_non_scalar_variant_passed_through checks that a dict variant ({"variant": "red", "reason": "SPLIT"}) is returned unchanged. (3) Bucketing is unchanged: bucket position depends only on bucket_by, the CBOR and mmh3 hash, and the weights. test_fractional_computed_variant_selected_by_weight checks that the weighted bucket is selected. The code at head confirms the existing logic. The PR summary states that the whole-PR diff could not be read, so the change scope relies on the head files and the AI-generated summary. The head test file was read directly. The tests were not executed in this assessment. The 'evaluate once' property is supported by the computed-variant test but no call-count test exists.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the Fraction.variant and fractional type annotations in custom_ops.py (+3/-2, per summary) and three added tests in tests/test_targeting.py (+28 lines). The type annotation changes match the requirement that variants are not rejected by result type. The tests cover the computed-variant, weight-selection, and pass-through requirements of #482. No unrelated functional changes were identified in the head files read. The whole-PR diff could not be read, so this conclusion rests on the head file contents and the summary.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 75301ea3-0859-4be7-b899-e386b4966bb5
Commits

Reviewing files that changed from the base of the PR and between bb44357 and 62bda8d.

Files selected for processing: 2

  • tools/openfeature-flagd-core/src/openfeature/contrib/tools/flagd/core/targeting/custom_ops.py
  • tools/openfeature-flagd-core/tests/test_targeting.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

This branch has not been deployed

No deployments
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.

feat: allow computed fractional bucket variants

1 participant