Flagsmith / Flagsmith/flagsmith
Race conditions are met with HTTP 500 by Core API
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 567
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 121
Description
We're regularly seeing `IntegrityError` logs (example below) pop up, often because of poorly orchestrated scripts or racing frontend code.
We should come up with a unified approach to these. The expectation is that the backend should handle the conflicts opaquely, or clearly indicate to the client why the request couldn't go through. Options are:
a) Consider wrapping mutating operations in transactions — unlikely outcome as we don't want to increase lock contention.
b) Return 409 Conflict — a bit tricky as it'd take some heuristics to accurately detect race-related `IntegrityErrors`.
Sentry Issue: [FLAGSMITH-API-5GY](https://flagsmith.sentry.io/issues/7222748629/?referrer=github_integration)
```
UniqueViolation: duplicate key value violates unique constraint "lowercase_feature_name"
DETAIL: Key (lower(name::text), project_id)=(pltn.objectbuilder.fixemptypagerace, 13318) already exists.
File "django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
IntegrityError: duplicate key value violates unique constraint "lowercase_feature_name"
DETAIL: Key (lower(name::text), project_id)=(pltn.objectbuilder.fixemptypagerace, 13318) already exists.
(29 additional frame(s) were not displayed)
...
File "features/views.py", line 270, in perform_create
serializer.save(
File "features/serializers.py", line 367, in create
feature = super().create(validated_data)
File "features/serializers.py", line 219, in create
instance = super(CreateFeatureSerializer, self).create(validated_data) # type: ignore[no-untyped-call]
```
Contributor guide
Assessment
This issue has not been assessed yet.