# precondition_failed

The change was based on a version of the resource that is no longer current (412).

## Meaning

- Admin API: an update of a user (`PATCH /v1/admin/orgs/{slug}/users/{id}`) whose
  `If-Match` names an `ETag` the user is no longer at. Someone changed the user's
  username, email, its verification or attributes since the caller read it: another
  administrator, the user editing their own attributes, or the user following a
  verification link. A sign-in, a lock, a status change or a password change does not
  advance the `ETag`.
- The check and the write are one conditional statement, so of two updates sent with
  the same `ETag` exactly one is applied and the other gets this answer.
- A proxy in front of the server that rewrites the `ETag` beyond marking it weak, such
  as Apache's `mod_deflate` appending `-gzip`, makes every update look stale. A tag
  marked weak (`W/"7"`) names the same revision and is accepted.

## Impact

Nothing changed. It is the protection working: without it the update would have
silently replaced the other change, and since `attributes` replaces the whole map, an
attribute a colleague added would have disappeared. An administrator in the dashboard
is asked to reload the user before saving again.

## Diagnosis

1. Look the request id up on the Troubleshooting page. The refusal is recorded as
   `user.updated` with reason `conflict` and cause `concurrent_update`.
2. Find the change that landed in between: the user's audit trail on the dashboard
   shows a `user.updated` (`self_service` when the user made it) or
   `auth.email_verification.completed` record after the caller's read.
3. If nothing landed in between, open the browser's network panel on the user's page:
   the `GET` of the user answers an `ETag` of the revision alone (`"7"`, or `W/"7"`).
   Anything added inside the quotes (`"7-gzip"`) was rewritten by a proxy on the way.

## Mitigation

- As an administrator: reload the user, check the other change, and make yours again.
- As an admin-API developer: read the user again (`GET`), apply your change to what it
  returns, and send it with the new `ETag`. Retry once; a loop that reapplies a stale
  edit without looking defeats the check. Omit `If-Match` only where overwriting
  whatever is current is what you mean.

## Escalation

Escalate when an update is refused although nothing changed the user since it was
read, for example when the `ETag` of two reads in a row differs. Open an issue with
the request ids, both `ETag` values and the server version.

---

[Problem code runbooks](https://www.nauthera.io/docs/v1/runbooks/problems) · Generated from [`internal/runbook/problems.yaml`](https://github.com/nauthera/nauthera-server/blob/main/internal/runbook/problems.yaml) in nauthera-server.
