feat(flags): implement get_feature_flag endpoint in SDK compliance adapter#500
feat(flags): implement get_feature_flag endpoint in SDK compliance adapter#500marandaneto merged 4 commits intomainfrom
Conversation
posthog-python Compliance ReportDate: 2026-04-16 10:50:55 UTC ✅ All Tests Passed!30/30 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 1/1 tests passed View Details
|
Prompt To Fix All With AIThis is a comment left during a code review.
Path: sdk_compliance_adapter/adapter.py
Line: 378-393
Comment:
**Inverted default makes endpoint always return `None`**
With `force_remote` defaulting to `False`, the mapping `only_evaluate_locally=not force_remote` sets `only_evaluate_locally=True`. Because the adapter client is initialised without a `personal_api_key`, `_locally_evaluate_flag` never loads flags, always returns `None`, and with `only_evaluate_locally=True` there is no remote fallback — so every unauthenticated call to this endpoint silently returns `{"success": true, "value": null}`.
The SDK's own default for `only_evaluate_locally` is `False` (local first, remote fallback). To preserve that default the `force_remote` default must be `True`:
```suggestion
force_remote = data.get("force_remote", True)
if not key:
return jsonify({"error": "key is required"}), 400
if not distinct_id:
return jsonify({"error": "distinct_id is required"}), 400
value = state.client.get_feature_flag(
key,
distinct_id,
person_properties=person_properties,
groups=groups,
group_properties=group_properties,
disable_geoip=disable_geoip,
only_evaluate_locally=not force_remote,
)
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "implement flags endpoint" | Re-trigger Greptile |
The test harness reads capabilities from /health to determine which test suites to run. Without this field, all suites are skipped, resulting in 0/0 tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
@marandaneto Thanks! Wasn't expecting a review yet. Created this as part of testing the SDK harness addition upstream so I could verify that it worked as intended. But I think it's ready to go as it is now, so thanks! 👍 FYI the plan forward is to add such an adapter to all SDK's that support flags (all I guess?), so we can automatically test that the comply with the flags API and behave similarly wrt. to edge cases, etc. |
we can merge it and fix if needed |
Problem
The SDK compliance adapter doesn't expose a way to evaluate feature flags, which is needed for cross-SDK compliance testing of flag evaluation.
Changes
/get_feature_flagPOST endpoint to the compliance adapter that wrapsclient.get_feature_flag()person_properties,groups,group_properties,disable_geoip, andforce_remoteparametersforce_remoteto the inverse ofonly_evaluate_locallyfor a cleaner external APITesting
/get_feature_flagendpoint with akeyanddistinct_idafter initializing the SDK via the adapterkeyordistinct_idare missing or SDK is not initialized