Skip to content

Race conditions are met with HTTP 500 by Core API  #6617

@sentry

Description

@sentry

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiIssue related to the REST APIgood first issueGood for newcomers

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions