Model

Module containing the base Model class along with it’s utility classes. Also defining two attributes, specific for the Model subclasses only.

exception model.AlreadyRemovedError(model)

Exception raised when trying to save (via Model.save() method) an already deleted model (the method Model.delete() was called).

Parameters

model (Model) – Instance of a model that has been deleted

msg = 'Model `{}` was already removed and cannot be updated anymore.'
class model.State

Base class for all other states of the model creating a state machine (state design pattern).

save(model)

According to a current state, does whatever is appropriate for saving the entity. Must be implemented in every subclass.

Parameters

model (model.Model) – model to perform the “save” operation on

Returns

instance of the next state

Return type

model.State

delete(model)

According to a current state, does whatever is appropriate for removing the entity. Must be implemented in every subclass.

Parameters

model (model.Model) – model to perform the “delete” operation on

Returns

instance of the next state

Return type

model.State

class model.NewState

State of an entity that does not yet exist on the server, but an instance of a corresponding model is already created.

save(model)

Creates new entity on the server.

Parameters

model (model.Model) – model to perform the “save” operation on

Returns

instance of class:ExistingState class

Return type

model.State

delete(model)

Does nothing as the entity doesn’t really exist.

Parameters

model (model.Model) – model to perform the “delete” operation on

Returns

instance of class:DeletedState class

Return type

model.State

class model.ExistingState

State of an entity that exists on the server.

save(model)

Updates the entity on the server.

Parameters

model (model.Model) – model to perform the “save” operation on

Returns

self

Return type

model.State

delete(model)

Removes the entity on the server.

Parameters

model (model.Model) – model to perform the “delete” operation on

Returns

instance of class:DeletedState class

Return type

model.State

class model.DeletedState

State of an entity that was on the server, but has been deleted and now exists only an instance of a corresponding model.

save(model)

This always raises an AlreadyRemovedError exception as it is invalid operation. Cannot update an entity that does not exist anymore.

Parameters

model (model.Model) – model to perform the “save” operation on

Raises

AlreadyRemovedError always

Return type

NoReturn

delete(model)

Does nothing as the entity is already deleted on the server.

Parameters

model (model.Model) – model to perform the “delete” operation on

Returns

self

Return type

model.State

class model.Model(sdk, **kwargs)

This is the base class for all the data stewardship wizard data entities. Defines the one attribute that is common for all entities – UUID.

It tracks it’s own state and according to this state it can decide, which operation to do when calling the save() and delete() methods.

For tracking of changes, snapshots (Snapshot class) are used.

It also modifies a behavior of it’s parent, AttributesMixin class – when the attribute is not yet set, it does not raise. Instead None value is returned.

If you, for some reason, want to just create a model for an entity that already exists on the server and you have all the required data, do:

# 1
>>> model = Model(None, __update_attrs={'uuid': '123'})
>>> model.uuid
'123'

# 2
>>> model = Model(None)
>>> model._update_attrs(uuid='123')
>>> model.uuid
'123'

In either case, the model will be set with correct state.

Parameters
  • sdk – instance of the DataStewardshipWizardSDK class

  • kwargs – arbitrary attributes that can be set on this entity

uuid: str
save()

If there are some changes to save, persist them on the server. It will either create or update the entity, according to it’s state.

Raises

AlreadyRemovedError if the entity was already deleted

delete()

Deletes the entity. Particular actions depend on entity’s internal state.

attrs()

Gets all attributes with non-None value.

Returns

dict with all entity’s attributes, excluding the None values

Return type

Dict[str, Any]

class model.ModelAttribute(type_, **kwargs)

Attribute containing another Model instance.

Parameters

type_ (TypingType[AttributesMixin]) – type of the attribute

Keyword arguments
  • default (Any): default value for the attribute

  • nullable (bool): whether None should be a valid value

  • read_only (bool): if set to True, assigning to this attribute will raise an exception

  • immutable (bool): if set to True, it’s possible to assign a value to this attribute only once; any other try will raise an exception

  • choices (Sequence[Any]): sequence defining range of possible values

class model.ListOfModelsAttribute(model_class, **kwargs)

Attribute containing a list of another Model instances.

Parameters
  • type_ – type of the attribute

  • model_class (Type[Model]) –

Keyword arguments
  • default (Any): default value for the attribute

  • nullable (bool): whether None should be a valid value

  • read_only (bool): if set to True, assigning to this attribute will raise an exception

  • immutable (bool): if set to True, it’s possible to assign a value to this attribute only once; any other try will raise an exception

  • choices (Sequence[Any]): sequence defining range of possible values