Flagsmith / Flagsmith/flagsmith

Environment feature versions are not importable via `loaddata`

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

Description

**Symptom:** `loaddata` raises `DeserializationError` for any organisation that has an environment with `use_v2_feature_versioning = True`.

**Root cause:** `EnvironmentFeatureVersionManager` ([features/versioning/managers.py:16](https://github.com/Flagsmith/flagsmith/blob/main/api/features/versioning/managers.py#L16)) inherits from `SoftDeleteManager` but is missing `UUIDNaturalKeyManagerMixin`. Every other exportable manager in the codebase includes this mixin. Without it, Django serialises FK references to `EnvironmentFeatureVersion` (on `FeatureState.environment_feature_version` and `FeatureSegment.environment_feature_version`) as a natural-key list `[""]`, but the deserialiser cannot resolve the list back to an object because `get_by_natural_key` does not exist on the manager.

**Fix:** One-line change — add the mixin:

```python
class EnvironmentFeatureVersionManager(UUIDNaturalKeyManagerMixin, SoftDeleteManager):
```

This follows the exact pattern of `FeatureManager`, `FeatureStateManager`, `FeatureSegmentManager`, and `SoftDeleteExportableManager`.

**Test:** Use tests from https://github.com/Flagsmith/flagsmith/pull/6765 to verify the correctness of the solution.

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.