Flagsmith/flagsmith

Race conditions are met with HTTP 500 by Core API

Open

#6,617 建立於 2026年1月28日

在 GitHub 查看
 (5 留言) (0 反應) (0 負責人)Python (3,475 star) (264 fork)batch import
apigood first issue

描述

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

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]

貢獻者指南

Race conditions are met with HTTP 500 by Core API · Flagsmith/flagsmith#6617 | Good First Issue