Skip to content

service

A generic service object implementation.

Service object is generic on the domain model type, which should be a SQLAlchemy model.

Service

Service(**repo_kwargs)

Bases: Generic[ModelT]

Generic Service object.

Parameters:

Name Type Description Default
**repo_kwargs Any

passed as keyword args to repo instantiation.

{}

__class_getitem__ classmethod

__class_getitem__(item)

Set repository_type from generic parameter.

create async

create(data)

Wrap repository instance creation.

Parameters:

Name Type Description Default
data ModelT

Representation to be created.

required

Returns:

Type Description
ModelT

Representation of created instance.

delete async

delete(id_)

Wrap repository delete operation.

Parameters:

Name Type Description Default
id_ Any

Identifier of instance to be deleted.

required

Returns:

Type Description
ModelT

Representation of the deleted instance.

enqueue_background_task async

enqueue_background_task(method_name, **kwargs)

Enqueue an async callback for the operation and data.

Parameters:

Name Type Description Default
method_name str

Method on the service object that should be called by the async worker.

required
**kwargs Any

Arguments to be passed to the method when called. Must be JSON serializable.

{}

get async

get(id_)

Wrap repository scalar operation.

Parameters:

Name Type Description Default
id_ Any

Identifier of instance to be retrieved.

required

Returns:

Type Description
ModelT

Representation of instance with identifier id_.

list async

list(*filters, **kwargs)

Wrap repository scalars operation.

Parameters:

Name Type Description Default
*filters FilterTypes

Collection route filters.

()
**kwargs Any

Keyword arguments for attribute based filtering.

{}

Returns:

Type Description
list[ModelT]

The list of instances retrieved from the repository.

update async

update(id_, data)

Wrap repository update operation.

Parameters:

Name Type Description Default
id_ Any

Identifier of item to be updated.

required
data ModelT

Representation to be updated.

required

Returns:

Type Description
ModelT

Updated representation.

upsert async

upsert(id_, data)

Wrap repository upsert operation.

Parameters:

Name Type Description Default
id_ Any

Identifier of the object for upsert.

required
data ModelT

Representation for upsert.

required

Returns:

Type Description
ModelT

Updated or created representation.

ServiceException

Bases: Exception

Base class for Service related exceptions.

UnauthorizedException

Bases: ServiceException

A user tried to do something they shouldn't have.

make_service_callback async

make_service_callback(
    _ctx, *, service_module_name, service_type_fqdn, service_method_name, **kwargs
)

Make an async service callback.

Parameters:

Name Type Description Default
_ctx Context

the SAQ context

required
service_module_name str

Module of service type to instantiate.

required
service_type_fqdn str

Reference to service type in module.

required
service_method_name str

Method to be called on the service object.

required
**kwargs Any

Unpacked into the service method call as keyword arguments.

{}