Objects API#

fastapi_restly.objects provides the session-level object primitives: building and updating SQLAlchemy objects from schema input, flushing and deleting them, and snapshotting loaded column values.

async fastapi_restly.objects.async_delete_object(session: AsyncSession, obj: object) → None#

Async equivalent of delete_object().

async fastapi_restly.objects.async_make_new_object(session: AsyncSession, model_cls: type[_T], schema_obj: BaseModel) → _T#

Async equivalent of make_new_object().

async fastapi_restly.objects.async_save_object(session: AsyncSession, obj: _T) → _T#

Async equivalent of save_object().

async fastapi_restly.objects.async_update_object(session: AsyncSession, obj: _T, schema_obj: BaseModel) → _T#

Async equivalent of update_object().

fastapi_restly.objects.delete_object(session: Session, obj: object) → None#

Delete obj and flush the session.

fastapi_restly.objects.make_new_object(session: Session, model_cls: type[_T], schema_obj: BaseModel) → _T#

Build model_cls from schema_obj and add it to session.

This is the schema-to-ORM mapping primitive. It resolves Restly reference fields, skips read-only inputs, applies schema defaults, and stages the object in the session. It does not flush and does not run a view’s create business logic.

schema_obj’s own schema decides what is written: every field it declares, except those it marks ReadOnly.

fastapi_restly.objects.save_object(session: Session, obj: _T) → _T#

Flush the session and refresh obj from the database.

The refresh names obj’s own attributes, so it does not cascade into related objects; see _refresh_plan().

fastapi_restly.objects.snapshot(obj: Any) → dict[str, Any]#

Frozen capture of an object’s already-loaded column values, for old-vs-new dirty detection in the commit hooks.

Not copy(obj) (which shares SQLAlchemy instance state). Reads only attributes already present on the instance, so it never triggers a lazy load: a deferred/unloaded column is skipped instead of forcing a blocking SELECT (which on an async session would raise MissingGreenlet). No session argument: it reads state already on the instance.

fastapi_restly.objects.update_object(session: Session, obj: _T, schema_obj: BaseModel) → _T#

Apply writable fields from schema_obj to obj.

This is the schema-to-ORM update primitive. It resolves Restly reference fields and applies only writable inputs: the fields the client sent that schema_obj’s own schema does not mark ReadOnly. It does not flush and does not run a view’s update business logic.

See also

Customizing RestView covers the view-bound counterparts of these helpers and includes the domain-utilities table.