Skip to content

service

A generic service object implementation.

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

Operation

Bases: str, Enum

Operation type markers sent with callbacks.

Service

Service(session)

Bases: Generic[ModelT]

Generic Service object.

Parameters:

Name Type Description Default
repository

Instance conforming to AbstractRepository interface.

required

__init_subclass__

__init_subclass__(*args, **kwargs)

Create and cache a DTO instance that is internal use only.

note

This pattern could be changed to on first access, rather than at compile time.

authorize_create async

authorize_create(data)

Control resource creation.

Can use self.user here.

Parameters:

Name Type Description Default
data ModelT

The object to be created.

required

Returns:

Type Description
ModelT

The object with restricted attribute values removed.

authorize_delete async

authorize_delete(id_)

Authorize delete of item.

Parameters:

Name Type Description Default
id_ Any

Identifier of item to be retrieved.

required

authorize_get async

authorize_get(id_)

Authorize get of item.

Parameters:

Name Type Description Default
id_ Any

Identifier of item to be retrieved.

required

authorize_list async

authorize_list()

Authorize collection access.

authorize_update async

authorize_update(id_, data)

Authorize update of item.

Parameters:

Name Type Description Default
id_ Any

Identifier of the object to be updated.

required
data ModelT

The object to be updated.

required

Returns:

Type Description
ModelT

ModelT

authorize_upsert async

authorize_upsert(id_, data)

Authorize upsert of item.

Parameters:

Name Type Description Default
id_ Any

The identifier of the resource to upsert.

required
data ModelT

The object to be updated.

required

Returns:

Type Description
ModelT

ModelT

create async

create(data)

Wraps 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_)

Wraps 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_callback async

enqueue_callback(operation, data)

Enqueue an async callback for the operation and data.

Parameters:

Name Type Description Default
operation Operation

Operation performed on data.

required
data ModelT

The data for the operation.

required

get async

get(id_)

Wraps 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)

Wraps 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.

receive_callback async

receive_callback(operation, raw_obj)

Method called by the async workers.

Do what you want in here but remember not to block the loop.

Parameters:

Name Type Description Default
operation Operation

Operation performed on the object.

required
raw_obj dict[str, Any]

Raw representation of the object.

required

update async

update(id_, data)

Wraps 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)

Wraps 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, operation, raw_obj)

Function that makes the async service callbacks.

Parameters:

Name Type Description Default
_ctx dict

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
operation Operation

Operation performed on the instance.

required
raw_obj dict[str, Any]

Data received from the work queue.

required