fix(api): handle DoesNotExist in audit log signals and webhooks#6938
fix(api): handle DoesNotExist in audit log signals and webhooks#6938wavebyrd wants to merge 1 commit intoFlagsmith:mainfrom
Conversation
|
Someone is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
34c9c6d to
bb99b2b
Compare
…smith#6879) When a related FeatureState or FeatureSegment is deleted before the async create_audit_log_from_historical_record task runs, the signals and mappers crash with DoesNotExist errors. Handle these gracefully: - audit/signals.py: catch FeatureState.DoesNotExist in send_feature_flag_went_live_signal and skip the signal - integrations/grafana/mappers.py: catch ObjectDoesNotExist in _get_instance_tags_from_audit_log_record and return empty tags - features/tasks.py: catch ObjectDoesNotExist when accessing feature_state.feature_segment and fall back to None
|
Fixed the rebase - now showing only the single commit for this fix. Apologies for the messy history! |
bb99b2b to
b01891f
Compare
emyller
left a comment
There was a problem hiding this comment.
As I understand these changes, they will eliminate the error by suppressing it.
Similarly to this other pull request, the solution could be suppressing it, but it could also be avoiding it.
Either way, I think this needs deeper investigation, as did the pull request linked above, in order to make sure we're fixing the problem correctly, and not hiding others silently.
@wavebyrd Again, thanks for your contribution. Allow us time to investigate what needs to be done here, or feel free to take another stab with this review in mind — though I think it needs effort to reproduce and investigate the user journey in detail.
Summary
Fixes #6879
When a FeatureState or FeatureSegment is deleted before the async
create_audit_log_from_historical_recordtask runs, three locations crash with DoesNotExist errors (reported via Sentry as FLAGSMITH-API-5JA, 5JB, 5JD).This handles DoesNotExist gracefully in all three locations:
audit/signals.py-send_feature_flag_went_live_signal: catchesFeatureState.DoesNotExistwhen accessingaudited_instance.feature_stateand skips the signalintegrations/grafana/mappers.py-_get_instance_tags_from_audit_log_record: catchesObjectDoesNotExistand returns empty tags (annotation is still created, just without feature/segment tags)features/tasks.py-_get_feature_state_webhook_data: catchesObjectDoesNotExistwhen accessingfeature_state.feature_segmentand falls back toNoneChanges
api/audit/signals.pyapi/integrations/grafana/mappers.py[]api/features/tasks.pyNoneapi/tests/unit/audit/test_unit_audit_signals.pyapi/tests/unit/integrations/grafana/test_mappers.pyapi/tests/unit/features/test_unit_features_tasks.pyTest plan
test_send_feature_flag_went_live_signal__deleted_feature_state__skips_signaltest_map_audit_log_record_to_grafana_annotation__deleted_feature_state__returns_no_instance_tagstest_get_feature_state_webhook_data__deleted_feature_segment__returns_data