Flagsmith / Flagsmith/flagsmith

Payload for Webhook Emitted on Flag Reset for Identity is Inaccurate

Open
#2,102 4 comments 0 reactions 1 assignee Claimed by @dabeeeenster View on GitHub
bug
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 14h
Merged PRs (30d)
124

Description

**Describe the bug**
When a feature is toggled for an identity to override an environment default, and later that feature is reset for the identity, the payload of emitted webhook is not accurate.

**To Reproduce**

Steps to reproduce the behavior:

0. Have a feature which defaults to off
1. Toggle the feature on for an identity (webhook is emitted)
2. Reset the feature for the identity (webhook is emitted)
3. Observe the emitted webhook payload incorrectly describes the new_state: `data.new_state.enabled == true`.

**Expected behavior**

3. The new_state in the webhook payload should correspond to the default state of the feature for the environment

**How are you running Flagsmith?**

- [X] SaaS at flagsmith.com

**Additional context**

I first brought this up in #148, so I'll just repeat my comment verbatim below because that issue was closed. I want to emphasize, however, that the problem statement of #148 _is not true_. Webhooks _are emitted_ when someone resets the state for an identity! #148 was labeled as tech debt to introduce a desired feature, but I am opening this issue as a bug because the functionality exists but is incorrect.

--------------

The behavior I'm seeing here is that a webhook is sent when a feature is reset for an identity, however, the resulting payload shows `enabled: true` when the default is false. Here's an example (with some redactions) of a webhook payload emitted when resetting a feature that defaults to off:

```yaml
data:
changed_by: me
new_state:
enabled: true
feature:
created_date: 2021-10-28T15:41:35.074466Z
default_enabled: false
description: Maintenance Mode
id: 13637
initial_value: null
name: '@perm:maintenance-mode'
type: STANDARD
feature_segment: null
feature_state_value: null
identity: 49679244
identity_identifier: me
previous_state:
enabled: true
feature:
created_date: 2021-10-28T15:41:35.074466Z
default_enabled: false
description: Maintenance Mode
id: 13637
initial_value: null
name: '@perm:maintenance-mode'
type: STANDARD
feature_segment: null
feature_state_value: null
identity: 49679244
identity_identifier: me
timestamp: 2023-04-04T17:43:55.031610Z
event_type: FLAG_UPDATED
```

Note that `data.new_state.enabled == true` even though `data.new_state.feature.default_enabled == false`. The expectation is that `data.new_state.enabled == data.new_state.feature.default_enabled` when resetting a feature for an identity.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.