aiida.storage.psql_dos.orm package#
Implementation of ORM backend entities.
Submodules#
Module for the SqlAlchemy backend implementation of the AuthInfo ORM class.
- class aiida.storage.psql_dos.orm.authinfos.SqlaAuthInfo(backend, computer, user)[source]#
Bases:
aiida.storage.psql_dos.orm.entities.SqlaModelEntity
[aiida.storage.psql_dos.models.authinfo.DbAuthInfo
],aiida.orm.implementation.authinfos.BackendAuthInfo
SqlAlchemy backend implementation for the AuthInfo ORM class.
- COMPUTER_CLASS#
- MODEL_CLASS#
- USER_CLASS#
- __abstractmethods__ = frozenset({})#
- __init__(backend, computer, user)[source]#
Construct a new instance.
- Parameters
computer – a
aiida.orm.implementation.computers.BackendComputer
instanceuser – a
aiida.orm.implementation.users.BackendUser
instance
- Returns
an
aiida.orm.implementation.authinfos.BackendAuthInfo
instance
- __module__ = 'aiida.storage.psql_dos.orm.authinfos'#
- __orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.authinfo.DbAuthInfo], <class 'aiida.orm.implementation.authinfos.BackendAuthInfo'>)#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- property computer#
Return the computer associated with this instance.
- property enabled: bool#
Return whether this instance is enabled.
- Returns
boolean, True if enabled, False otherwise
- get_auth_params()[source]#
Return the dictionary of authentication parameters
- Returns
a dictionary with authentication parameters
- property id#
Get the id of this entity
- Returns
the entity id
- property is_stored: bool#
Return whether the entity is stored.
- Returns
True if stored, False otherwise
- set_auth_params(auth_params)[source]#
Set the dictionary of authentication parameters
- Parameters
auth_params – a dictionary with authentication parameters
- set_metadata(metadata)[source]#
Set the dictionary of metadata
- Parameters
metadata – a dictionary with metadata
- property user#
Return the user associated with this instance.
- class aiida.storage.psql_dos.orm.authinfos.SqlaAuthInfoCollection(backend: StorageBackend)[source]#
Bases:
aiida.orm.implementation.authinfos.BackendAuthInfoCollection
The collection of SqlAlchemy backend AuthInfo entries.
- ENTITY_CLASS#
- __module__ = 'aiida.storage.psql_dos.orm.authinfos'#
- __parameters__ = ()#
SQLA implementations for the Comment entity and collection.
- class aiida.storage.psql_dos.orm.comments.SqlaComment(backend, node, user, content=None, ctime=None, mtime=None)[source]#
Bases:
aiida.storage.psql_dos.orm.entities.SqlaModelEntity
[aiida.storage.psql_dos.models.comment.DbComment
],aiida.orm.implementation.comments.BackendComment
Comment implementation for Sqla.
- MODEL_CLASS#
- USER_CLASS#
- __abstractmethods__ = frozenset({})#
- __init__(backend, node, user, content=None, ctime=None, mtime=None)[source]#
Construct a SqlaComment.
- Parameters
node – a Node instance
user – a User instance
content – the comment content
ctime – The creation time as datetime object
mtime – The modification time as datetime object
- __module__ = 'aiida.storage.psql_dos.orm.comments'#
- __orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.comment.DbComment], <class 'aiida.orm.implementation.comments.BackendComment'>)#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- property content#
Return the comment content.
- property ctime#
Return the creation time of the comment.
- property mtime#
Return the modified time of the comment.
- property node#
Return the comment’s node.
- property user#
Return the comment owner.
- class aiida.storage.psql_dos.orm.comments.SqlaCommentCollection(backend: StorageBackend)[source]#
Bases:
aiida.orm.implementation.comments.BackendCommentCollection
SqlAlchemy implementation for the CommentCollection.
- ENTITY_CLASS#
- __module__ = 'aiida.storage.psql_dos.orm.comments'#
- __parameters__ = ()#
- create(node, user, content=None, **kwargs)[source]#
Create a Comment for a given node and user
- Parameters
node – a Node instance
user – a User instance
content – the comment content
- Returns
a Comment object associated to the given node and user
- delete(comment_id)[source]#
Remove a Comment from the collection with the given id
- Parameters
comment_id (int) – the id of the comment to delete
- Raises
TypeError – if
comment_id
is not an intNotExistent – if Comment with ID
comment_id
is not found
- delete_all()[source]#
Delete all Comment entries.
- Raises
IntegrityError – if all Comments could not be deleted
SqlAlchemy implementations for the Computer entity and collection.
- class aiida.storage.psql_dos.orm.computers.SqlaComputer(backend, **kwargs)[source]#
Bases:
aiida.storage.psql_dos.orm.entities.SqlaModelEntity
[aiida.storage.psql_dos.models.computer.DbComputer
],aiida.orm.implementation.computers.BackendComputer
SqlAlchemy implementation for BackendComputer.
- MODEL_CLASS#
- __abstractmethods__ = frozenset({})#
- __module__ = 'aiida.storage.psql_dos.orm.computers'#
- __orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.computer.DbComputer], <class 'aiida.orm.implementation.computers.BackendComputer'>)#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- property description#
Return the description of the computer.
- property hostname#
Return the hostname of the computer (used to associate the connected device).
- property id#
Get the id of this entity
- Returns
the entity id
- property is_stored#
Is this entity stored?
- Returns
True if stored, False otherwise
- property label#
Return the (unique) label of the computer.
- property pk#
Return the id for this entity.
This is unique only amongst entities of this type for a particular backend.
- Returns
the entity id
- property uuid#
Return the UUID of the computer.
- class aiida.storage.psql_dos.orm.computers.SqlaComputerCollection(backend: StorageBackend)[source]#
Bases:
aiida.orm.implementation.computers.BackendComputerCollection
Collection of Computer instances.
- ENTITY_CLASS#
- __module__ = 'aiida.storage.psql_dos.orm.computers'#
- __parameters__ = ()#
Module to get the backend instance from the Models instance
- aiida.storage.psql_dos.orm.convert._(dbmodel, backend)[source]#
Convert a dblink to the backend entity
- aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel, backend)[source]#
- aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: aiida.storage.psql_dos.models.user.DbUser, backend)
- aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: aiida.storage.psql_dos.models.group.DbGroup, backend)
- aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: aiida.storage.psql_dos.models.computer.DbComputer, backend)
- aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: aiida.storage.psql_dos.models.node.DbNode, backend)
- aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: aiida.storage.psql_dos.models.authinfo.DbAuthInfo, backend)
- aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: aiida.storage.psql_dos.models.comment.DbComment, backend)
- aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: aiida.storage.psql_dos.models.log.DbLog, backend)
- aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: aiida.storage.psql_dos.models.node.DbLink, backend)
Default get_backend_entity
Classes and methods for Django specific backend entities
- class aiida.storage.psql_dos.orm.entities.SqlaModelEntity(*args, **kwargs)[source]#
Bases:
Generic
[aiida.storage.psql_dos.orm.entities.ModelType
]A mixin that adds some common SQLA backend entity methods
- MODEL_CLASS = None#
- __annotations__ = {'_model': <class 'aiida.storage.psql_dos.orm.utils.ModelWrapper'>}#
- __dict__ = mappingproxy({'__module__': 'aiida.storage.psql_dos.orm.entities', '__annotations__': {'_model': <class 'aiida.storage.psql_dos.orm.utils.ModelWrapper'>}, '__doc__': 'A mixin that adds some common SQLA backend entity methods', 'MODEL_CLASS': None, '_class_check': <classmethod object>, 'from_dbmodel': <classmethod object>, '__init__': <function SqlaModelEntity.__init__>, 'model': <property object>, 'bare_model': <property object>, 'id': <property object>, 'is_stored': <property object>, 'store': <function SqlaModelEntity.store>, '_flush_if_stored': <function SqlaModelEntity._flush_if_stored>, '__orig_bases__': (typing.Generic[~ModelType],), '__dict__': <attribute '__dict__' of 'SqlaModelEntity' objects>, '__weakref__': <attribute '__weakref__' of 'SqlaModelEntity' objects>, '__parameters__': (~ModelType,)})#
- __module__ = 'aiida.storage.psql_dos.orm.entities'#
- __orig_bases__ = (typing.Generic[~ModelType],)#
- __parameters__ = (~ModelType,)#
- __weakref__#
list of weak references to the object (if defined)
- property bare_model#
Return the underlying SQLA ORM model for this entity.
Warning
Getting/setting attributes on this model bypasses AiiDA’s internal update/flush mechanisms.
- classmethod from_dbmodel(dbmodel, backend)[source]#
Create an AiiDA Entity from the corresponding SQLA ORM model and storage backend
- Parameters
dbmodel – the SQLAlchemy model to create the entity from
backend – the corresponding storage backend
- Returns
the AiiDA entity
- property model: aiida.storage.psql_dos.orm.utils.ModelWrapper#
Return an ORM model that correctly updates and flushes the data when getting or setting a field.
Mixin class for SQL implementations of extras
.
- class aiida.storage.psql_dos.orm.extras_mixin.ExtrasMixin[source]#
Bases:
object
Mixin class for SQL implementations of
extras
.- __annotations__ = {'bare_model': typing.Any, 'is_stored': <class 'bool'>, 'model': typing.Any}#
- __dict__ = mappingproxy({'__module__': 'aiida.storage.psql_dos.orm.extras_mixin', '__annotations__': {'model': typing.Any, 'bare_model': typing.Any, 'is_stored': <class 'bool'>}, '__doc__': 'Mixin class for SQL implementations of ``extras``.', 'extras': <property object>, 'get_extra': <function ExtrasMixin.get_extra>, 'set_extra': <function ExtrasMixin.set_extra>, 'set_extra_many': <function ExtrasMixin.set_extra_many>, 'reset_extras': <function ExtrasMixin.reset_extras>, 'delete_extra': <function ExtrasMixin.delete_extra>, 'delete_extra_many': <function ExtrasMixin.delete_extra_many>, 'clear_extras': <function ExtrasMixin.clear_extras>, 'extras_items': <function ExtrasMixin.extras_items>, 'extras_keys': <function ExtrasMixin.extras_keys>, '__dict__': <attribute '__dict__' of 'ExtrasMixin' objects>, '__weakref__': <attribute '__weakref__' of 'ExtrasMixin' objects>})#
- __module__ = 'aiida.storage.psql_dos.orm.extras_mixin'#
- __weakref__#
list of weak references to the object (if defined)
- bare_model: Any#
- model: Any#
SQLA groups
- class aiida.storage.psql_dos.orm.groups.SqlaGroup(backend, label, user, description='', type_string='')[source]#
Bases:
aiida.storage.psql_dos.orm.entities.SqlaModelEntity
[aiida.storage.psql_dos.models.group.DbGroup
],aiida.storage.psql_dos.orm.extras_mixin.ExtrasMixin
,aiida.orm.implementation.groups.BackendGroup
The SQLAlchemy Group object
- GROUP_NODE_CLASS#
- MODEL_CLASS#
- NODE_CLASS#
- USER_CLASS#
- __abstractmethods__ = frozenset({})#
- __init__(backend, label, user, description='', type_string='')[source]#
Construct a new SQLA group
- Parameters
backend – the backend to use
label – the group label
user – the owner of the group
description – an optional group description
type_string – an optional type for the group to contain
- __module__ = 'aiida.storage.psql_dos.orm.groups'#
- __orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.group.DbGroup], <class 'aiida.storage.psql_dos.orm.extras_mixin.ExtrasMixin'>, <class 'aiida.orm.implementation.groups.BackendGroup'>)#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- add_nodes(nodes, **kwargs)[source]#
Add a node or a set of nodes to the group.
- Note
all the nodes and the group itself have to be stored.
- Parameters
nodes – a list of BackendNode instance to be added to this group
kwargs – skip_orm: When the flag is on, the SQLA ORM is skipped and SQLA is used to create a direct SQL INSERT statement to the group-node relationship table (to improve speed).
- count()[source]#
Return the number of entities in this group.
- Returns
integer number of entities contained within the group
- property description#
Return the description of the group as a string.
- property is_stored#
Is this entity stored?
- Returns
True if stored, False otherwise
- property label#
Return the name of the group as a string.
- property nodes#
Get an iterator to all the nodes in the group
- property pk#
Return the id for this entity.
This is unique only amongst entities of this type for a particular backend.
- Returns
the entity id
- remove_nodes(nodes, **kwargs)[source]#
Remove a node or a set of nodes from the group.
- Note
all the nodes and the group itself have to be stored.
- Parameters
nodes – a list of BackendNode instance to be added to this group
kwargs – skip_orm: When the flag is set to True, the SQLA ORM is skipped and SQLA is used to create a direct SQL DELETE statement to the group-node relationship table in order to improve speed.
- property type_string#
Return the string defining the type of the group.
- property user#
Return a backend user object, representing the user associated to this group.
- property uuid#
Return the UUID of the group.
- class aiida.storage.psql_dos.orm.groups.SqlaGroupCollection(backend: StorageBackend)[source]#
Bases:
aiida.orm.implementation.groups.BackendGroupCollection
The SLQA collection of groups
- ENTITY_CLASS#
- __module__ = 'aiida.storage.psql_dos.orm.groups'#
- __parameters__ = ()#
SQLA Log and LogCollection module
- class aiida.storage.psql_dos.orm.logs.SqlaLog(backend, time, loggername, levelname, dbnode_id, message='', metadata=None)[source]#
Bases:
aiida.storage.psql_dos.orm.entities.SqlaModelEntity
[aiida.storage.psql_dos.models.log.DbLog
],aiida.orm.implementation.logs.BackendLog
SQLA Log backend entity
- MODEL_CLASS#
- __abstractmethods__ = frozenset({})#
- __module__ = 'aiida.storage.psql_dos.orm.logs'#
- __orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.log.DbLog], <class 'aiida.orm.implementation.logs.BackendLog'>)#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- property dbnode_id#
Get the id of the object that created the log entry
- property levelname#
The name of the log level
- property loggername#
The name of the logger that created this entry
- property message#
Get the message corresponding to the entry
- property metadata#
Get the metadata corresponding to the entry
- property time#
Get the time corresponding to the entry
- property uuid#
Get the string representation of the UUID of the log entry
- class aiida.storage.psql_dos.orm.logs.SqlaLogCollection(backend: StorageBackend)[source]#
Bases:
aiida.orm.implementation.logs.BackendLogCollection
The SQLA collection for logs
- ENTITY_CLASS#
- __module__ = 'aiida.storage.psql_dos.orm.logs'#
- __parameters__ = ()#
- delete(log_id)[source]#
Remove a Log entry from the collection with the given id
- Parameters
log_id (int) – id of the Log to delete
- Raises
TypeError – if
log_id
is not an intNotExistent – if Log with ID
log_id
is not found
- delete_all()[source]#
Delete all Log entries.
- Raises
IntegrityError – if all Logs could not be deleted
SqlAlchemy implementation of the BackendNode and BackendNodeCollection classes.
- class aiida.storage.psql_dos.orm.nodes.SqlaNode(backend, node_type, user, computer=None, process_type=None, label='', description='', ctime=None, mtime=None)[source]#
Bases:
aiida.storage.psql_dos.orm.entities.SqlaModelEntity
[aiida.storage.psql_dos.models.node.DbNode
],aiida.storage.psql_dos.orm.extras_mixin.ExtrasMixin
,aiida.orm.implementation.nodes.BackendNode
SQLA Node backend entity
- COMPUTER_CLASS#
- LINK_CLASS#
- MODEL_CLASS#
- USER_CLASS#
- __abstractmethods__ = frozenset({})#
- __init__(backend, node_type, user, computer=None, process_type=None, label='', description='', ctime=None, mtime=None)[source]#
Construct a new BackendNode instance wrapping a new DbNode instance.
- Parameters
backend – the backend
node_type – the node type string
user – associated BackendUser
computer – associated BackendComputer
label – string label
description – string description
ctime – The creation time as datetime object
mtime – The modification time as datetime object
- __module__ = 'aiida.storage.psql_dos.orm.nodes'#
- __orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.node.DbNode], <class 'aiida.storage.psql_dos.orm.extras_mixin.ExtrasMixin'>, <class 'aiida.orm.implementation.nodes.BackendNode'>)#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- add_incoming(source, link_type, link_label)[source]#
Add a link of the given type from a given node to ourself.
- Parameters
source – the node from which the link is coming
link_type – the link type
link_label – the link label
- Returns
True if the proposed link is allowed, False otherwise
- Raises
TypeError – if source is not a Node instance or link_type is not a LinkType enum
ValueError – if the proposed link is invalid
aiida.common.ModificationNotAllowed – if either source or target node is not stored
- property attributes#
Return the complete attributes dictionary.
Warning
While the entity is unstored, this will return references of the attributes on the database model, meaning that changes on the returned values (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the entity is stored, the returned attributes will be a deep copy and mutations of the database attributes will have to go through the appropriate set methods. Therefore, once stored, retrieving a deep copy can be a heavy operation. If you only need the keys or some values, use the iterators attributes_keys and attributes_items, or the getters get_attribute and get_attribute_many instead.
- Returns
the attributes as a dictionary
- attributes_items() Iterable[Tuple[str, Any]] [source]#
Return an iterator over the attributes.
- Returns
an iterator with attribute key value pairs
- attributes_keys() Iterable[str] [source]#
Return an iterator over the attribute keys.
- Returns
an iterator with attribute keys
- clean_values()[source]#
Clean the values of the node fields.
This method is called before storing the node. The purpose of this method is to convert data to a type which can be serialized and deserialized for storage in the DB without its value changing.
- clone()[source]#
Return an unstored clone of ourselves.
- Returns
an unstored BackendNode with the exact same attributes and extras as self
- property computer#
Return the computer of this node.
- Returns
the computer or None
- property ctime#
Return the node ctime.
- Returns
the ctime
- delete_attribute(key: str) None [source]#
Delete an attribute.
- Parameters
key – name of the attribute
- Raises
AttributeError – if the attribute does not exist
- delete_attribute_many(keys: Iterable[str]) None [source]#
Delete multiple attributes.
- Parameters
keys – names of the attributes to delete
- Raises
AttributeError – if at least one of the attribute does not exist
- property description#
Return the node description.
- Returns
the description
- get_attribute(key: str) Any [source]#
Return the value of an attribute.
Warning
While the entity is unstored, this will return a reference of the attribute on the database model, meaning that changes on the returned value (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the entity is stored, the returned attribute will be a deep copy and mutations of the database attributes will have to go through the appropriate set methods.
- Parameters
key – name of the attribute
- Returns
the value of the attribute
- Raises
AttributeError – if the attribute does not exist
- property label#
Return the node label.
- Returns
the label
- property mtime#
Return the node mtime.
- Returns
the mtime
- property node_type#
Return the node type.
- Returns
the node type
- property process_type#
Return the node process type.
- Returns
the process type
- property repository_metadata#
Return the node repository metadata.
- Returns
the repository metadata
- reset_attributes(attributes: Dict[str, Any]) None [source]#
Reset the attributes.
Note
This will completely clear any existing attributes and replace them with the new dictionary.
- Parameters
attributes – a dictionary with the attributes to set
- set_attribute(key: str, value: Any) None [source]#
Set an attribute to the given value.
- Parameters
key – name of the attribute
value – value of the attribute
- set_attribute_many(attributes: Dict[str, Any]) None [source]#
Set multiple attributes.
Note
This will override any existing attributes that are present in the new dictionary.
- Parameters
attributes – a dictionary with the attributes to set
- store(links=None, with_transaction=True, clean=True)[source]#
Store this entity
- Returns
the entity itself
- property user#
Return the user of this node.
- Returns
the user
- property uuid#
Return the node UUID.
- Returns
the string representation of the UUID
- class aiida.storage.psql_dos.orm.nodes.SqlaNodeCollection(backend: StorageBackend)[source]#
Bases:
aiida.orm.implementation.nodes.BackendNodeCollection
The collection of Node entries.
- ENTITY_CLASS#
- __annotations__ = {'ENTITY_CLASS': typing.Type[aiida.storage.psql_dos.orm.nodes.SqlaNode]}#
- __module__ = 'aiida.storage.psql_dos.orm.nodes'#
- __parameters__ = ()#
SQLA user
- class aiida.storage.psql_dos.orm.users.SqlaUser(backend, email, first_name, last_name, institution)[source]#
Bases:
aiida.storage.psql_dos.orm.entities.SqlaModelEntity
[aiida.storage.psql_dos.models.user.DbUser
],aiida.orm.implementation.users.BackendUser
SQLA user
- MODEL_CLASS#
- __abstractmethods__ = frozenset({})#
- __module__ = 'aiida.storage.psql_dos.orm.users'#
- __orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.user.DbUser], <class 'aiida.orm.implementation.users.BackendUser'>)#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- property email#
Get the email address of the user
- Returns
the email address
- property first_name#
Get the user’s first name
- Returns
the first name
- property institution#
Get the user’s institution
- Returns
the institution
- property last_name#
Get the user’s last name
- Returns
the last name
- class aiida.storage.psql_dos.orm.users.SqlaUserCollection(backend: StorageBackend)[source]#
Bases:
aiida.orm.implementation.users.BackendUserCollection
Collection of SQLA Users
- ENTITY_CLASS#
- __module__ = 'aiida.storage.psql_dos.orm.users'#
- __parameters__ = ()#
Utilities for the implementation of the SqlAlchemy backend.
- class aiida.storage.psql_dos.orm.utils.ModelWrapper(model, backend: PsqlDosBackend)[source]#
Bases:
object
Wrap an SQLA ORM model and AiiDA storage backend instance together, to correctly update and flush the data model when getting or setting a field.
The ORM model represents a row in a database table, with a given schema, and its attributes represent the fields (a.k.a. columns) of the table. When an ORM model instance is created, it does not have any association with a particular database, i.e. it is “unsaved”. At this point, its attributes can be freely retrieved or set.
When the ORM model instance is saved, it is associated with the database configured for the backend instance, by adding it to the backend instances’s session (i.e. its connection with the database). At this point:
Whenever we retrieve a field of the model instance, unless we know it to be immutable, we first ensure that the field represents the latest value in the database (e.g. in case the database has been externally updated).
Whenever we set a field of the model instance, unless we know it to be immutable, we flush the change to the database.
- __dict__ = mappingproxy({'__module__': 'aiida.storage.psql_dos.orm.utils', '__doc__': 'Wrap an SQLA ORM model and AiiDA storage backend instance together,\n to correctly update and flush the data model when getting or setting a field.\n\n The ORM model represents a row in a database table, with a given schema,\n and its attributes represent the fields (a.k.a. columns) of the table.\n When an ORM model instance is created, it does not have any association with a particular database,\n i.e. it is "unsaved".\n At this point, its attributes can be freely retrieved or set.\n\n When the ORM model instance is saved, it is associated with the database configured for the backend instance,\n by adding it to the backend instances\'s session (i.e. its connection with the database).\n At this point:\n\n - Whenever we retrieve a field of the model instance, unless we know it to be immutable,\n we first ensure that the field represents the latest value in the database\n (e.g. in case the database has been externally updated).\n\n - Whenever we set a field of the model instance, unless we know it to be immutable,\n we flush the change to the database.\n\n ', '__init__': <function ModelWrapper.__init__>, 'session': <property object>, '__getattr__': <function ModelWrapper.__getattr__>, '__setattr__': <function ModelWrapper.__setattr__>, 'is_saved': <function ModelWrapper.is_saved>, 'save': <function ModelWrapper.save>, '_is_mutable_model_field': <function ModelWrapper._is_mutable_model_field>, '_is_model_field': <function ModelWrapper._is_model_field>, '_flush': <function ModelWrapper._flush>, '_ensure_model_uptodate': <function ModelWrapper._ensure_model_uptodate>, '_in_transaction': <function ModelWrapper._in_transaction>, '__dict__': <attribute '__dict__' of 'ModelWrapper' objects>, '__weakref__': <attribute '__weakref__' of 'ModelWrapper' objects>, '__annotations__': {}})#
- __getattr__(item)[source]#
Get an attribute of the model instance.
If the model is saved in the database, the item corresponds to a mutable model field and the current scope is not in an open database connection, then the field’s value is first refreshed from the database.
- Parameters
item – the name of the model field
- Returns
the value of the model’s attribute
- __init__(model, backend: PsqlDosBackend)[source]#
Construct the ModelWrapper.
- Parameters
model – the ORM model instance to wrap
backend – the storage backend instance
- __module__ = 'aiida.storage.psql_dos.orm.utils'#
- __setattr__(key, value)[source]#
Set the attribute on the model instance.
If the field being set is a mutable model field and the model is saved, the changes are flushed.
- Parameters
key – the name of the model field
value – the value to set
- __weakref__#
list of weak references to the object (if defined)
- _ensure_model_uptodate(fields=None)[source]#
Refresh all fields of the wrapped model instance by fetching the current state of the database instance.
- Parameters
fields – optionally refresh only these fields, if None all fields are refreshed.
- _flush(fields=())[source]#
Flush the fields of the model to the database.
Note
If the wrapped model is not actually saved in the database yet, this method is a no-op.
- Parameters
fields – the model fields whose current value to flush to the database
- _in_transaction()[source]#
Return whether the current scope is within an open database transaction.
- Returns
boolean, True if currently in open transaction, False otherwise.
- _is_model_field(field)[source]#
Return whether the field is a field of the model.
- Returns
boolean, True if the field is a model field, False otherwise.
- _is_mutable_model_field(field)[source]#
Return whether the field is a mutable field of the model.
- Returns
boolean, True if the field is a model field and is not in the IMMUTABLE_MODEL_FIELDS set.
- is_saved()[source]#
Return whether the wrapped model instance is saved in the database.
- Returns
boolean, True if the model is saved in the database, False otherwise
- save()[source]#
Store the model instance.
Note
If one is currently in a transaction, this method is a no-op.
- Raises
aiida.common.IntegrityError – if a database integrity error is raised during the save.
- property session: sqlalchemy.orm.session.Session#
Return the session of the storage backend instance.
- aiida.storage.psql_dos.orm.utils.disable_expire_on_commit(session)[source]#
Context manager that disables expire_on_commit and restores the original value on exit
- Parameters
session (
sqlalchemy.orm.session.Session
) – The SQLA session