Flagsmith/flagsmith

Race conditions are met with HTTP 500 by Core API

Open

#6,617 创建于 2026年1月28日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)Python (264 fork)batch import
apigood first issue

仓库指标

Star
 (3,475 star)
PR 合并指标
 (平均合并 3天 7小时) (30 天内合并 157 个 PR)

描述

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]

贡献者指南