Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/local-properties-align.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"posthog-ruby": patch
Comment thread
marandaneto marked this conversation as resolved.
"posthog-rails": patch
---

Align local `is_set` and `is_not_set` evaluation with partial property context.
3 changes: 1 addition & 2 deletions lib/posthog/feature_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ def self.semver_wildcard_bounds(value)

def self.match_property(property, property_values, cohort_properties = {})
# only looks for matches where key exists in property_values
# doesn't support operator is_not_set

PostHog::Utils.symbolize_keys! property
PostHog::Utils.symbolize_keys! property_values
Expand All @@ -629,7 +628,7 @@ def self.match_property(property, property_values, cohort_properties = {})
if !property_values.key?(key)
raise InconclusiveMatchError, "Property #{key} not found in property_values"
elsif operator == 'is_not_set'
raise InconclusiveMatchError, 'Operator is_not_set not supported'
return false
end

override_value = property_values[key]
Expand Down
19 changes: 18 additions & 1 deletion spec/posthog/feature_flag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1439,15 +1439,32 @@ module PostHog

expect(FeatureFlagsPoller.match_property(property_a, { 'key' => 'value' })).to be true
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => 'value2' })).to be true
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => '' })).to be true
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => nil })).to be true
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => false })).to be true
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => 0 })).to be true
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => '' })).to be true
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => [] })).to be true
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => {} })).to be true

expect do
FeatureFlagsPoller.match_property(property_a, { 'key2' => 'value' })
end.to raise_error(InconclusiveMatchError)
expect { FeatureFlagsPoller.match_property(property_a, {}) }.to raise_error(InconclusiveMatchError)
end

it 'with operator is_not_set' do
property_a = { 'key' => 'key', 'value' => 'is_not_set', 'operator' => 'is_not_set' }

expect(FeatureFlagsPoller.match_property(property_a, { 'key' => nil })).to be false
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => false })).to be false
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => 0 })).to be false
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => '' })).to be false
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => [] })).to be false
expect(FeatureFlagsPoller.match_property(property_a, { 'key' => {} })).to be false

expect { FeatureFlagsPoller.match_property(property_a, {}) }.to raise_error(InconclusiveMatchError)
end

it 'with operator icontains' do
property_a = { 'key' => 'key', 'value' => 'vaLuE', 'operator' => 'icontains' }

Expand Down
Loading