Flagsmith / Flagsmith/flagsmith

Look into `tasks.create_audit_log_from_historical_record` error spike

Open
#5,668 1 comment 0 reactions 0 assignees View on GitHub
api bug
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

Description

💥 On 2025-06-27 we had a high error rate [reported by Sentry](https://flagsmith.sentry.io/alerts/rules/details/95470/?alert=411&environment=production). Despite the alarming rate, it quickly went down and did not show any issues in the product that we know of. It was very likely unnoticed and, as far as a quick investigation went, did not cause harm.

```
AttributeError: 'NoneType' object has no attribute 'segment_id'
File "task_processor/processor.py", line 136, in _run_task
future.result(timeout=timeout) # Wait for completion or timeout
File "concurrent/futures/_base.py", line 456, in result
return self.__get_result()
File "concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "task_processor/models.py", line 72, in run
return self.callable(*self.args, **self.kwargs)
File "audit/tasks.py", line 103, in create_audit_log_from_historical_record
if instance.get_skip_create_audit_log():
File "segments/models.py", line 359, in get_skip_create_audit_log
segment = self.rule.get_segment() # type: ignore[no-untyped-call]
File "segments/models.py", line 250, in get_segment
while not rule.segment_id:
```

📈 [According to Sentry](https://flagsmith.sentry.io/issues/6639916696?project=5544478): this exception was triggered ~370 times on 2025-06-27, and another ~450 times on 2025-06-24. The first time it was seen, it only happened 6 times on 2025-05-27.

Image

🤔 We're wondering if this was side effect of some large operation. From @matthewelwell:

> seems like some sort of issue around soft deletions. Perhaps a large project being deleted?

Let's look into it and:
- Investigate any damage.
- Prevent it.

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.