Saltar a contenido

dorm.contrib.asyncmodel

AsyncModel — Model variant that rejects sync ORM calls.

API

dorm.contrib.asyncmodel.AsyncModel

Bases: Model

Subclass this instead of :class:dorm.Model to forbid sync ORM access on the resulting class.

The async-only contract is enforced two ways:

  1. The default objects manager is replaced with an :class:AsyncOnlyManager — any sync class-level call (e.g. MyModel.objects.create(...)) raises :class:AsyncOnlyError.
  2. Instance-level :meth:save and :meth:delete raise the same error — callers must use :meth:asave and :meth:adelete.

Sub-classing rules: AsyncModel itself stays abstract (no table). Concrete subclasses get the strict-async behaviour automatically; you can still override objects if you want a custom async-only Manager subclass.

dorm.contrib.asyncmodel.AsyncOnlyManager

Bases: Manager

Manager that forwards async methods and rejects sync ones.

Async methods (aall, afilter, acreate, aget, etc.) hit the parent implementation untouched. Every sync method raises :class:AsyncOnlyError.

dorm.contrib.asyncmodel.AsyncOnlyError

Bases: RuntimeError

Raised when sync ORM API is called on an :class:AsyncModel.

Carries the offending method name for clearer test assertions and log messages. Subclasses :class:RuntimeError so generic error handlers degrade gracefully.