NoneType error in FeatureState.get_create_log_message when environment default is missing

Open Beginner friendly
#6,880 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
backend

Research direction

Start in features/models.py at line 941 and read get_create_log_message together with get_environment_default. Confirm the missing environment default path, then ensure the method no longer dereferences None and verify the intended audit-log behavior for that case.

Written by the indexing model from the issue text.

Description

api

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:

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:

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.

Dominant language
Python
Stars
6.6k
Forks
571
Avg merge
1d 16h
Merged PRs (30d)
116

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Flagsmith/flagsmith

All issues in Flagsmith/flagsmith

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.