Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuditLog creation fails when a segment override is deleted #4828

Open
1 of 4 tasks
uinstinct opened this issue Nov 12, 2024 · 0 comments · May be fixed by #4829
Open
1 of 4 tasks

AuditLog creation fails when a segment override is deleted #4828

uinstinct opened this issue Nov 12, 2024 · 0 comments · May be fixed by #4829
Labels
bug Something isn't working

Comments

@uinstinct
Copy link
Contributor

How are you running Flagsmith

  • Self Hosted with Docker
  • Self Hosted with Kubernetes
  • SaaS at flagsmith.com
  • Some other way (add details in description below)

Describe the bug

AuditLog (required for webhooks) is not created when a segment override (FeatureStateValue) is deleted

Attaching api server logs when this happens

[12/Nov/2024 12:39:28] "GET /api/v1/features/feature-segments/?environment=1&feature=2 HTTP/1.1" 200 52
FeatureSegment for second_button with priority 0
Exception in thread Thread-8 (create_audit_log_from_historical_record):
Traceback (most recent call last):
  File "/opt/miniconda3/envs/flagsmith/lib/python3.12/site-packages/django/db/models/fields/related_descriptors.py", line 218, in __get__
    rel_obj = self.field.get_cached_value(instance)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/flagsmith/lib/python3.12/site-packages/django/db/models/fields/mixins.py", line 15, in get_cached_value
Project proj p1 - Environment Development - Feature second_button - Enabled: True
    return instance._state.fields_cache[cache_name]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'feature_state'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/miniconda3/envs/flagsmith/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/opt/miniconda3/envs/flagsmith/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/instinct/Desktop/flagsmith/api/audit/tasks.py", line 94, in create_audit_log_from_historical_record
[12/Nov/2024 12:39:28] "GET /api/v1/features/featurestates/?environment=1&feature=2 HTTP/1.1" 200 1057
    environment, project = instance.get_environment_and_project()
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/instinct/Desktop/flagsmith/api/core/models.py", line 141, in get_environment_and_project
    environment, project = self._get_environment(), self._get_project()
                           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/instinct/Desktop/flagsmith/api/features/models.py", line 1136, in _get_environment
    return self.feature_state.environment
           ^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/flagsmith/lib/python3.12/site-packages/django/db/models/fields/related_descriptors.py", line 236, in __get__
    rel_obj = self.get_object(instance)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/flagsmith/lib/python3.12/site-packages/django/db/models/fields/related_descriptors.py", line 366, in get_object
    return super().get_object(instance)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/flagsmith/lib/python3.12/site-packages/django/db/models/fields/related_descriptors.py", line 199, in get_object
    return qs.get(self.field.get_reverse_related_filter(instance))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/flagsmith/lib/python3.12/site-packages/django/db/models/query.py", line 637, in get
    raise self.model.DoesNotExist(
features.models.FeatureState.DoesNotExist: FeatureState matching query does not exist.
[12/Nov/2024 12:39:28] "GET /api/v1/projects/1/features/2/ HTTP/1.1" 200 659

Steps To Reproduce

  1. Start the python api on a terminal to see the logs
  2. Open the a feature's settings and go to the Settings Overrides tab
  3. (if already a sample segment is present, you can skip this step) Create a new segment and click on "Update Segment Overrides"
  4. Delete the segment and again click on "Update Segment Overrides"
  5. Observe the api terminal and check the thrown error (same as the error pasted above)

Installation

  • local setup by cloning the repo and running the latest flagsmith api server and client on git main branch

Expected behavior

No errors to be thrown on the api server.
Audit Log should get created.

Screenshots

No response

@uinstinct uinstinct added the bug Something isn't working label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant