---
url: "https://vueda.dev/v3/reference/api/py/vueda.core.viewsets/WarningConfirmationMixin.md"
title: "WarningConfirmationMixin"
---

# WarningConfirmationMixin

## Overview

Gate writes behind an explicit confirmation when they report advisory warnings.

After validation succeeds (so blocking errors have already produced a 400) and before the
instance is written, the warnings source is consulted. If it returns warnings and the request
has not acknowledged them, a :class:`~vueda.core.exceptions.ConfirmationRequired` (HTTP 409) is
raised, withholding the save. The client surfaces the warnings, the user confirms, and the
resubmission carries the warnings digest in the ``Acknowledge-Warnings`` header, which matches
and lets the write proceed. A changed warning set yields a different digest and re-prompts.
The shared gate logic lives in :func:`~vueda.core.exceptions.gate_warnings`.

Raising before the write means nothing is committed, so this does not depend on the request
being wrapped in a transaction.

Warnings sources:

- Single-object ``create``/``update``: the serializer's ``get_warnings()``, consulted in
  ``perform_create``/``perform_update``. A serializer without ``get_warnings`` (including a
  ``ListSerializer`` wrapping a Vueda serializer, i.e. bulk writes) is skipped, so warnings on
  bulk/list saves are not surfaced.
- ``destroy``, ``activate``, and ``deactivate`` (single and bulk): ``get_warnings_for_object``
  for a single object, and ``get_warnings`` for a bulk request; called by
  ``VuedaViewSet.destroy`` and ``DeactivateActionViewSetMixin``. See their docstrings.

## `get_warnings` {#get_warnings}

Bulk warnings hook for actions that write without a per-object serializer.

``action`` is the action name string (``"destroy"``, ``"activate"``, or ``"deactivate"``)
and ``objs`` is a queryset of the affected instances for a bulk request. Return the
per-object ``{object_id: {field: [messages]}}`` shape, one entry per warned object keyed
by ``str(pk)``, so the client can attribute each warning back to its object.

The default calls ``get_warnings_for_object(action, obj)`` once per instance in ``objs``
and keys each non-empty result by ``str(obj.pk)``. Override ``get_warnings_for_object``
instead unless bulk needs its own logic (for example a single bulk-optimized query rather
than one check per instance).

### Signature {#get_warnings-signature}

`get_warnings(self, action, objs)`

#### Parameters {#get_warnings-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| self |  | yes |  |  |
| <span id="get_warnings-param-action">action</span> |  | yes |  |  |
| <span id="get_warnings-param-objs">objs</span> |  | yes |  |  |

### Source {#get_warnings-source}

`server/vueda/core/viewsets/__init__.py:193`

## `get_warnings_for_object` {#get_warnings_for_object}

Single-object warnings hook for actions that write without a per-object serializer.

``action`` is the action name string (``"destroy"``, ``"activate"``, or ``"deactivate"``)
and ``obj`` is the single affected instance. Return the aggregate ``{field: [messages]}``
shape (the same shape the serializer-level ``get_warnings()`` returns; use
``"non_field_errors"`` for a warning not tied to a field).

Called directly for a single-object request. The default ``get_warnings`` below also calls
this once per instance for a bulk request, keying each result by object id, so overriding
this hook alone gates both the single-object and bulk forms of ``action`` with the same
rule -- override ``get_warnings`` instead only if bulk needs different or bulk-optimized
logic.

The default returns ``{}``, meaning no confirmation is required.

### Signature {#get_warnings_for_object-signature}

`get_warnings_for_object(self, action, obj)`

#### Parameters {#get_warnings_for_object-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| self |  | yes |  |  |
| <span id="get_warnings_for_object-param-action">action</span> |  | yes |  |  |
| <span id="get_warnings_for_object-param-obj">obj</span> |  | yes |  |  |

### Source {#get_warnings_for_object-source}

`server/vueda/core/viewsets/__init__.py:174`

## `perform_create` {#perform_create}

### Signature {#perform_create-signature}

`perform_create(self, serializer)`

#### Parameters {#perform_create-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| self |  | yes |  |  |
| <span id="perform_create-param-serializer">serializer</span> |  | yes |  |  |

### Source {#perform_create-source}

`server/vueda/core/viewsets/__init__.py:215`

## `perform_update` {#perform_update}

### Signature {#perform_update-signature}

`perform_update(self, serializer)`

#### Parameters {#perform_update-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| self |  | yes |  |  |
| <span id="perform_update-param-serializer">serializer</span> |  | yes |  |  |

### Source {#perform_update-source}

`server/vueda/core/viewsets/__init__.py:219`

## Source

`server/vueda/core/viewsets/__init__.py:148`
