Flagsmith / Flagsmith/flagsmith
NoneType error in FeatureState.get_create_log_message when environment default is missing
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 567
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 121
Description
`AttributeError: 'NoneType' object has no attribute 'enabled'` in `features/models.py:941` — the `get_create_log_message` method calls `self.get_environment_default()` which returns `None`, then tries to access `.enabled` on it.
Sentry Issue: FLAGSMITH-API-5JG — all from the same trace during a bulk operation on project "snapshot-hdf1".
## Root Cause
At `features/models.py:941`:
```python
and self.enabled == self.get_environment_default().enabled # type: ignore[union-attr]
```
`get_environment_default()` returns `None` when the environment default `FeatureState` no longer exists (likely deleted concurrently). The existing `# type: ignore[union-attr]` comment acknowledges this possibility but doesn't handle it.
## Suggested Fix
Guard against `None`:
```python
env_default = self.get_environment_default()
if env_default is not None and self.enabled == env_default.enabled:
```
Or skip audit log creation when the environment default is missing.
Contributor guide
Assessment
This issue has not been assessed yet.