Skip to content

Types

SelectorSpec

SelectorSpec dataclass

Bases: Generic[ResultT, ExtraT]

All wiring for a single read action in one record.

Used as a value in action_specs on viewsets and as the spec= argument to :class:SelectorListView / :class:SelectorRetrieveView.

Generic parameters (both default to Any):

  • ResultT — the selector's return type.
  • ExtraT — a TypedDict describing the keys returned by kwargs.

Fields:

  • selector — callable invoked by get_queryset() (list) or get_object() (retrieve). None means "use the configured queryset / default DRF behaviour".
  • output_serializer — DRF Serializer subclass used by get_serializer_class() for this action. None falls back to DRF's standard serializer_class.
  • kwargs — callable returning extra kwargs to merge into the pool the selector receives. Co-locating it with the spec lets each action declare its own contract — no if self.action == ... branching in a catch-all get_selector_kwargs.

ServiceSpec

ServiceSpec dataclass

Bases: Generic[InputT, ResultT, ExtraT]

All wiring for a single mutation action in one record.

Used as a value in ServiceViewSet.service_specs and as the spec= argument to :func:service_action / :class:ServiceCreateView / :class:ServiceUpdateView / :class:ServiceDeleteView.

Generic parameters are optional and purely informational for type checkers:

  • InputT — the validated-data type produced by input_serializer. For dataclass-based serializers this is the dataclass; for plain ModelSerializer it is typically dict[str, Any].
  • ResultT — the value returned by the service callable, the input to output_selector (when set), and the value rendered by output_serializer.
  • ExtraT — a TypedDict describing the keys returned by kwargs.

All three default to Any, so ServiceSpec(service=fn) keeps working unchanged.

Fields mirror the kwargs that MutationFlowMixin._run_mutation forwards to the underlying flow runner. success_status is left as None so each consumer can supply its own action-appropriate default (201 for create, 200 for update, 204 for destroy).

kwargs is a callable that returns extra kwargs to merge into the pool the service receives. Co-locating it with the spec lets each action declare its own contract — no if self.action == ... branching in a catch-all get_service_kwargs. See :class:ServiceView for the attributes available on the view argument.

ChangeResult

ChangeResult dataclass

Outcome of a mutation helper call.

instance is the model instance after the mutation. created is True iff this came from :func:create_from_input / :func:acreate_from_input. changes records every field whose value actually differed from its prior value (or from UNSET for creates).

changed_fields property

changed_fields: tuple[str, ...]

Names of every field present in :attr:changes.

get_field_change

get_field_change(field_name: str) -> FieldChange | None

Return the :class:FieldChange for field_name, or None.

FieldChange

FieldChange dataclass

One field's before/after pair from a mutation.

old will be UNSET for fields populated as part of a create (no prior value existed).

UNSET

unset

The UNSET sentinel.

Used to distinguish "field omitted from input" from "field explicitly set to None". Critical for partial updates where None must not stomp on an existing value.