diff --git a/aiida/backends/djsite/db/migrations/0034_drop_node_columns_nodeversion_public.py b/aiida/backends/djsite/db/migrations/0034_drop_node_columns_nodeversion_public.py new file mode 100644 index 0000000000..3a0eb76a02 --- /dev/null +++ b/aiida/backends/djsite/db/migrations/0034_drop_node_columns_nodeversion_public.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +########################################################################### +# Copyright (c), The AiiDA team. All rights reserved. # +# This file is part of the AiiDA code. # +# # +# The code is hosted on GitHub at https://github.com/aiidateam/aiida_core # +# For further information on the license, see the LICENSE.txt file # +# For further information please visit http://www.aiida.net # +########################################################################### +# pylint: disable=invalid-name,too-few-public-methods +"""Drop the columns `nodeversion` and `public` from the `DbNode` model.""" +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +# Remove when https://github.com/PyCQA/pylint/issues/1931 is fixed +# pylint: disable=no-name-in-module,import-error,no-member +from django.db import migrations + +from aiida.backends.djsite.db.migrations import upgrade_schema_version + +REVISION = '1.0.34' +DOWN_REVISION = '1.0.33' + + +class Migration(migrations.Migration): + """Drop the columns `nodeversion` and `public` from the `DbNode` model.""" + + dependencies = [ + ('db', '0033_replace_text_field_with_json_field'), + ] + + operations = [ + migrations.RemoveField( + model_name='dbnode', + name='nodeversion', + ), + migrations.RemoveField( + model_name='dbnode', + name='public', + ), + upgrade_schema_version(REVISION, DOWN_REVISION) + ] diff --git a/aiida/backends/djsite/db/migrations/__init__.py b/aiida/backends/djsite/db/migrations/__init__.py index 5a60739520..7022211870 100644 --- a/aiida/backends/djsite/db/migrations/__init__.py +++ b/aiida/backends/djsite/db/migrations/__init__.py @@ -22,7 +22,7 @@ class DeserializationException(AiidaException): pass -LATEST_MIGRATION = '0033_replace_text_field_with_json_field' +LATEST_MIGRATION = '0034_drop_node_columns_nodeversion_public' def _update_schema_version(version, apps, schema_editor): diff --git a/aiida/backends/djsite/db/models.py b/aiida/backends/djsite/db/models.py index ea903afaf7..864eb997e9 100644 --- a/aiida/backends/djsite/db/models.py +++ b/aiida/backends/djsite/db/models.py @@ -156,8 +156,7 @@ class DbNode(m.Model): ctime = m.DateTimeField(default=timezone.now, db_index=True, editable=False) mtime = m.DateTimeField(auto_now=True, db_index=True, editable=False) # Cannot delete a user if something is associated to it - user = m.ForeignKey(AUTH_USER_MODEL, on_delete=m.PROTECT, - related_name='dbnodes') + user = m.ForeignKey(AUTH_USER_MODEL, on_delete=m.PROTECT, related_name='dbnodes') # Direct links outputs = m.ManyToManyField('self', symmetrical=False, @@ -166,15 +165,7 @@ class DbNode(m.Model): # Used only if dbnode is a calculation, or remotedata # Avoid that computers can be deleted if at least a node exists pointing # to it. - dbcomputer = m.ForeignKey('DbComputer', null=True, on_delete=m.PROTECT, - related_name='dbnodes') - - # Index that is incremented every time a modification is done on itself or on attributes. - # Managed by the aiida.orm.Node class. Do not modify - nodeversion = m.IntegerField(default=1, editable=False) - - # For the API: whether this node - public = m.BooleanField(default=False) + dbcomputer = m.ForeignKey('DbComputer', null=True, on_delete=m.PROTECT, related_name='dbnodes') objects = m.Manager() # Return aiida Node instances or their subclasses instead of DbNode instances diff --git a/aiida/backends/djsite/manage.py b/aiida/backends/djsite/manage.py index 4b5425ce3c..a499bb0414 100644 --- a/aiida/backends/djsite/manage.py +++ b/aiida/backends/djsite/manage.py @@ -34,8 +34,10 @@ # I remove the argument I just read actual_argv = [actual_argv[0]] + actual_argv[2:] - # Load the general load_dbenv. - from aiida.backends.utils import load_dbenv - load_dbenv(profile=profile_name) + # Load the profile + from aiida.manage.configuration import load_profile + from aiida.manage.manager import get_manager + load_profile(profile_name) + get_manager().get_backend() execute_from_command_line(actual_argv) diff --git a/aiida/backends/sqlalchemy/migrations/versions/1830c8430131_drop_node_columns_nodeversion_public.py b/aiida/backends/sqlalchemy/migrations/versions/1830c8430131_drop_node_columns_nodeversion_public.py new file mode 100644 index 0000000000..e460ef9c12 --- /dev/null +++ b/aiida/backends/sqlalchemy/migrations/versions/1830c8430131_drop_node_columns_nodeversion_public.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +"""Drop the columns `nodeversion` and `public` from the `DbNode` model. + +Revision ID: 1830c8430131 +Revises: 1b8ed3425af9 +Create Date: 2019-05-27 15:35:37.404644 + +""" +# pylint: disable=invalid-name,no-member,import-error,no-name-in-module +from __future__ import division +from __future__ import print_function +from __future__ import absolute_import + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = '1830c8430131' +down_revision = '1b8ed3425af9' +branch_labels = None +depends_on = None + + +def upgrade(): + op.drop_column('db_dbnode', 'nodeversion') + op.drop_column('db_dbnode', 'public') + + +def downgrade(): + op.add_column('db_dbnode', sa.Column('public', sa.BOOLEAN(), autoincrement=False, nullable=True)) + op.add_column('db_dbnode', sa.Column('nodeversion', sa.INTEGER(), autoincrement=False, nullable=True)) diff --git a/aiida/backends/sqlalchemy/models/node.py b/aiida/backends/sqlalchemy/models/node.py index 9fc00bb446..f9758e2d67 100644 --- a/aiida/backends/sqlalchemy/models/node.py +++ b/aiida/backends/sqlalchemy/models/node.py @@ -37,8 +37,6 @@ class DbNode(Base): description = Column(Text(), nullable=True, default='') ctime = Column(DateTime(timezone=True), default=timezone.now) mtime = Column(DateTime(timezone=True), default=timezone.now, onupdate=timezone.now) - nodeversion = Column(Integer, default=1) - public = Column(Boolean, default=False) attributes = Column(JSONB) extras = Column(JSONB) diff --git a/aiida/backends/sqlalchemy/tests/test_session.py b/aiida/backends/sqlalchemy/tests/test_session.py index c3896136ed..cca2467c8b 100644 --- a/aiida/backends/sqlalchemy/tests/test_session.py +++ b/aiida/backends/sqlalchemy/tests/test_session.py @@ -211,10 +211,6 @@ def do_value_checks(attr_name, original, changed): for str_attr in ['label', 'description']: do_value_checks(str_attr, 'original', 'changed') - # Since we already changed an attribute twice, the starting nodeversion is 3 and not 1 - do_value_checks('nodeversion', 3, 4) - do_value_checks('public', True, False) - for str_attr in ['ctime', 'mtime']: do_value_checks(str_attr, timezone.now(), timezone.now()) diff --git a/aiida/backends/tests/fixtures/calcjob/arithmetic.add_old.aiida b/aiida/backends/tests/fixtures/calcjob/arithmetic.add_old.aiida index a4da480507..272211b09f 100644 Binary files a/aiida/backends/tests/fixtures/calcjob/arithmetic.add_old.aiida and b/aiida/backends/tests/fixtures/calcjob/arithmetic.add_old.aiida differ diff --git a/aiida/backends/tests/orm/implementation/test_nodes.py b/aiida/backends/tests/orm/implementation/test_nodes.py index fa45592fd7..b1639665a3 100644 --- a/aiida/backends/tests/orm/implementation/test_nodes.py +++ b/aiida/backends/tests/orm/implementation/test_nodes.py @@ -52,8 +52,6 @@ def test_creation(self): self.assertTrue(isinstance(node.ctime, datetime)) self.assertIsNone(node.mtime) self.assertIsNone(node.process_type) - self.assertEqual(node.public, False) - self.assertEqual(node.version, 1) self.assertEqual(node.attributes, dict()) self.assertEqual(node.extras, dict()) self.assertEqual(node.node_type, self.node_type) @@ -81,8 +79,6 @@ def test_creation(self): self.assertTrue(isinstance(node.ctime, datetime)) self.assertTrue(isinstance(node.mtime, datetime)) self.assertIsNone(node.process_type) - self.assertEqual(node.public, False) - self.assertEqual(node.version, 1) self.assertEqual(node.attributes, dict()) self.assertEqual(node.extras, dict()) self.assertEqual(node.node_type, self.node_type) @@ -92,11 +88,10 @@ def test_creation(self): # Try to construct a UUID from the UUID value to prove that it has a valid UUID UUID(node.uuid) - # Change a column, which should trigger the save, update the mtime and version, but leave the ctime untouched + # Change a column, which should trigger the save, update the mtime but leave the ctime untouched node.label = 'test' self.assertEqual(node.ctime, node_ctime) self.assertTrue(node.mtime > node_mtime) - self.assertEqual(node.version, 2) def test_creation_with_time(self): """ diff --git a/aiida/backends/tests/test_nodes.py b/aiida/backends/tests/test_nodes.py index 918ad63cbb..03bada715f 100644 --- a/aiida/backends/tests/test_nodes.py +++ b/aiida/backends/tests/test_nodes.py @@ -949,44 +949,6 @@ def test_attr_listing(self): self.assertEquals(a.extras, all_extras) - def test_versioning(self): - """ - Test the versioning of the node when setting attributes and extras - """ - a = orm.Data() - attrs_to_set = { - 'bool': self.boolval, - 'integer': self.intval, - 'float': self.floatval, - 'string': self.stringval, - 'dict': self.dictval, - 'list': self.listval, - } - - for key, value in attrs_to_set.items(): - a.set_attribute(key, value) - self.assertEquals(a.get_attribute(key), value) - - a.store() - - # Check after storing - for key, value in attrs_to_set.items(): - self.assertEquals(a.get_attribute(key), value) - - # Even if I stored many attributes, this should stay at 1 - self.assertEquals(a.version, 1) - - # I check increment on new version - a.set_extra('a', 'b') - self.assertEquals(a.version, 2) - - # In both cases, the node version must increase - a.label = 'test' - self.assertEquals(a.version, 3) - - a.description = 'test description' - self.assertEquals(a.version, 4) - def test_delete_extras(self): """ Checks the ability of deleting extras, also when they are dictionaries @@ -1145,25 +1107,6 @@ def test_basetype_as_extra(self): self.assertEqual(n.get_extra('a')['b'][0], "sometext3") self.assertIsInstance(n.get_extra('a')['b'][0], six.string_types) - def test_versioning_lowlevel(self): - """ - Checks the versioning. - """ - a = orm.Data() - a.store() - - # Even if I stored many attributes, this should stay at 1 - self.assertEquals(a.version, 1) - - a.label = "label1" - a.label = "label2" - self.assertEquals(a.version, 3) - - a.description = "desc1" - a.description = "desc2" - a.description = "desc3" - self.assertEquals(a.version, 6) - def test_comments(self): # This is the best way to compare dates with the stored ones, instead # of directly loading datetime.datetime.now(), or you can get a diff --git a/aiida/orm/implementation/django/convert.py b/aiida/orm/implementation/django/convert.py index e372e1f894..fd99ca55fa 100644 --- a/aiida/orm/implementation/django/convert.py +++ b/aiida/orm/implementation/django/convert.py @@ -173,9 +173,7 @@ def _(dbmodel, backend): label=dbmodel.label, description=dbmodel.description, dbcomputer_id=dbmodel.dbcomputer_id, - user_id=dbmodel.user_id, - public=dbmodel.public, - nodeversion=dbmodel.nodeversion) + user_id=dbmodel.user_id) from . import nodes return nodes.DjangoNode.from_dbmodel(djnode_instance, backend) diff --git a/aiida/orm/implementation/django/dummy_model.py b/aiida/orm/implementation/django/dummy_model.py index dc977ee7f2..4475eeaf46 100644 --- a/aiida/orm/implementation/django/dummy_model.py +++ b/aiida/orm/implementation/django/dummy_model.py @@ -160,10 +160,6 @@ class DbNode(Base): user_id = Column(Integer, ForeignKey('db_dbuser.id', deferrable=True, initially="DEFERRED"), nullable=False) user = relationship('DbUser', backref='dbnodes') - public = Column(Boolean, default=False) - - nodeversion = Column(Integer, default=1) - attributes = relationship('DbAttribute', uselist=True, backref='dbnode') extras = relationship('DbExtra', uselist=True, backref='dbnode') diff --git a/aiida/orm/implementation/django/nodes.py b/aiida/orm/implementation/django/nodes.py index d14c5d8dc7..77d07271c8 100644 --- a/aiida/orm/implementation/django/nodes.py +++ b/aiida/orm/implementation/django/nodes.py @@ -176,7 +176,6 @@ def set_attribute(self, key, value): :param value: value of the attribute """ self.ATTRIBUTE_CLASS.set_value_for_node(self.dbmodel, key, value) - self._increment_version_number() def set_attributes(self, attributes): """Set attributes. @@ -187,7 +186,6 @@ def set_attributes(self, attributes): """ for key, value in attributes.items(): self.ATTRIBUTE_CLASS.set_value_for_node(self.dbmodel, key, value) - self._increment_version_number() def reset_attributes(self, attributes): """Reset the attributes. @@ -197,7 +195,6 @@ def reset_attributes(self, attributes): :param attributes: the new attributes to set """ self.ATTRIBUTE_CLASS.reset_values_for_node(self.dbmodel, attributes) - self._increment_version_number() def delete_attribute(self, key): """Delete an attribute. @@ -262,16 +259,13 @@ def get_extras(self, keys): """ raise NotImplementedError - def set_extra(self, key, value, increase_version=True): + def set_extra(self, key, value): """Set an extra to the given value. :param key: name of the extra :param value: value of the extra - :param increase_version: boolean, if True will increase the node version upon successfully setting the extra """ self.EXTRA_CLASS.set_value_for_node(self.dbmodel, key, value) - if increase_version: - self._increment_version_number() def set_extras(self, extras): """Set extras. @@ -282,7 +276,6 @@ def set_extras(self, extras): """ for key, value in extras.items(): self.EXTRA_CLASS.set_value_for_node(self.dbmodel, key, value) - self._increment_version_number() def reset_extras(self, extras): """Reset the extras. @@ -398,11 +391,6 @@ def store(self, attributes=None, links=None, with_transaction=True): return self - def _increment_version_number(self): - """Increment the node version number of this node by one directly in the database.""" - self._dbmodel.nodeversion = self.version + 1 - self._dbmodel.save() - class DjangoNodeCollection(BackendNodeCollection): """The collection of Node entries.""" diff --git a/aiida/orm/implementation/nodes.py b/aiida/orm/implementation/nodes.py index 4ab8acb2e7..7a15d777a2 100644 --- a/aiida/orm/implementation/nodes.py +++ b/aiida/orm/implementation/nodes.py @@ -68,8 +68,6 @@ def process_type(self, value): :param value: the new value to set """ self._dbmodel.process_type = value - if self.is_stored: - self._increment_version_number() @property def label(self): @@ -86,8 +84,6 @@ def label(self, value): :param value: the new value to set """ self._dbmodel.label = value - if self.is_stored: - self._increment_version_number() @property def description(self): @@ -104,8 +100,6 @@ def description(self, value): :param value: the new value to set """ self._dbmodel.description = value - if self.is_stored: - self._increment_version_number() @abc.abstractproperty def computer(self): @@ -155,22 +149,6 @@ def mtime(self): """ return self._dbmodel.mtime - @property - def version(self): - """Return the node version. - - :return: the version - """ - return self._dbmodel.nodeversion - - @property - def public(self): - """Return the node public attribute. - - :return: the public attribute - """ - return self._dbmodel.public - @property def attributes(self): """Return the attributes dictionary. @@ -295,12 +273,11 @@ def get_extras(self, keys): """ @abc.abstractmethod - def set_extra(self, key, value, increase_version=True): + def set_extra(self, key, value): """Set an extra to the given value. :param key: name of the extra :param value: value of the extra - :param increase_version: boolean, if True will increase the node version upon successfully setting the extra """ @abc.abstractmethod @@ -379,10 +356,6 @@ def store(self, attributes=None, links=None, with_transaction=True): :parameter with_transaction: if False, do not use a transaction because the caller will already have opened one. """ - @abc.abstractmethod - def _increment_version_number(self): - """Increment the node version number of this node by one directly in the database.""" - @six.add_metaclass(abc.ABCMeta) class BackendNodeCollection(backends.BackendCollection[BackendNode]): diff --git a/aiida/orm/implementation/sqlalchemy/nodes.py b/aiida/orm/implementation/sqlalchemy/nodes.py index 2614b80941..eb6be8c534 100644 --- a/aiida/orm/implementation/sqlalchemy/nodes.py +++ b/aiida/orm/implementation/sqlalchemy/nodes.py @@ -177,7 +177,6 @@ def set_attribute(self, key, value): """ try: self.dbmodel.set_attr(key, value) - self._increment_version_number() except Exception: # pylint: disable=bare-except session = get_scoped_session() session.rollback() @@ -192,7 +191,6 @@ def set_attributes(self, attributes): """ try: self.dbmodel.set_attributes(attributes) - self._increment_version_number() except Exception: # pylint: disable=bare-except session = get_scoped_session() session.rollback() @@ -207,7 +205,6 @@ def reset_attributes(self, attributes): """ try: self.dbmodel.reset_attributes(attributes) - self._increment_version_number() except Exception: # pylint: disable=bare-except session = get_scoped_session() session.rollback() @@ -221,7 +218,6 @@ def delete_attribute(self, key): """ try: self._dbmodel.del_attr(key) - self._increment_version_number() except Exception: # pylint: disable=bare-except session = get_scoped_session() session.rollback() @@ -279,17 +275,14 @@ def get_extras(self, keys): """ raise NotImplementedError - def set_extra(self, key, value, increase_version=True): + def set_extra(self, key, value): """Set an extra to the given value. :param key: name of the extra :param value: value of the extra - :param increase_version: boolean, if True will increase the node version upon successfully setting the extra """ try: self._dbmodel.set_extra(key, value) - if increase_version: - self._increment_version_number() except Exception: # pylint: disable=bare-except session = get_scoped_session() session.rollback() @@ -304,7 +297,6 @@ def set_extras(self, extras): """ try: self.dbmodel.set_extras(extras) - self._increment_version_number() except Exception: # pylint: disable=bare-except session = get_scoped_session() session.rollback() @@ -319,7 +311,6 @@ def reset_extras(self, extras): """ try: self._dbmodel.reset_extras(extras) - self._increment_version_number() except Exception: # pylint: disable=bare-except session = get_scoped_session() session.rollback() @@ -333,7 +324,6 @@ def delete_extra(self, key): """ try: self._dbmodel.del_extra(key) - self._increment_version_number() except Exception: # pylint: disable=bare-except session = get_scoped_session() session.rollback() @@ -436,16 +426,6 @@ def store(self, attributes=None, links=None, with_transaction=True): return self - def _increment_version_number(self): - """Increment the node version number of this node by one directly in the database.""" - self._dbmodel.nodeversion = self.version + 1 - try: - self._dbmodel.save() - except Exception: # pylint: disable=bare-except - session = get_scoped_session() - session.rollback() - raise - class SqlaNodeCollection(BackendNodeCollection): """The collection of Node entries.""" diff --git a/aiida/orm/importexport.py b/aiida/orm/importexport.py index 740b05f4db..67e0509797 100644 --- a/aiida/orm/importexport.py +++ b/aiida/orm/importexport.py @@ -238,13 +238,11 @@ def get_all_fields_info(): "convert_type": "date" }, "uuid": {}, - "public": {}, "mtime": { "convert_type": "date" }, "node_type": {}, "label": {}, - "nodeversion": {}, "user": { "requires": USER_ENTITY_NAME, "related_name": "dbnodes" diff --git a/aiida/orm/nodes/node.py b/aiida/orm/nodes/node.py index e5bf9e7c6d..31ff295989 100644 --- a/aiida/orm/nodes/node.py +++ b/aiida/orm/nodes/node.py @@ -319,22 +319,6 @@ def mtime(self): """ return self.backend_entity.mtime - @property - def version(self): - """Return the node version. - - :return: the version - """ - return self.backend_entity.version - - @property - def public(self): - """Return the node public attribute. - - :return: the public attribute - """ - return self.backend_entity.public - @property def attributes(self): """Return the attributes dictionary. @@ -1062,7 +1046,7 @@ def _store(self, with_transaction=True): self._attrs_cache = {} self._incoming_cache = list() - self._backend_entity.set_extra(_HASH_EXTRA_KEY, self.get_hash(), increase_version=False) + self._backend_entity.set_extra(_HASH_EXTRA_KEY, self.get_hash()) return self @@ -1274,12 +1258,6 @@ def get_schema(): "is_foreign_key": False, "type": "unicode" }, - "nodeversion": { - "display_name": "Node version", - "help_text": "Version of the node", - "is_foreign_key": False, - "type": "int" - }, "process_type": { "display_name": "Process type", "help_text": "Process type", diff --git a/aiida/orm/querybuilder.py b/aiida/orm/querybuilder.py index 38a4f2bc14..db97f9f327 100644 --- a/aiida/orm/querybuilder.py +++ b/aiida/orm/querybuilder.py @@ -1043,7 +1043,7 @@ def _add_process_type_filter(self, tagspec, classifiers, subclassing): def add_projection(self, tag_spec, projection_spec): - """ + r""" Adds a projection :param tag_spec: A valid specification for a tag @@ -1080,13 +1080,13 @@ def add_projection(self, tag_spec, projection_spec): print type(qb.first()[0]) # >>> aiida.orm.nodes.data.structure.StructureData - The double start *\*\** projects all possible projections of this entity: + The double star ``**`` projects all possible projections of this entity: QueryBuilder().append(StructureData,tag='s', project='**').limit(1).dict()[0]['s'].keys() - # >>> u'user_id, description, ctime, label, extras, mtime, id, attributes, dbcomputer_id, nodeversion, type, public, uuid' + # >>> u'user_id, description, ctime, label, extras, mtime, id, attributes, dbcomputer_id, type, uuid' - Be aware that the result of *\*\** depends on the backend implementation. + Be aware that the result of ``**`` depends on the backend implementation. """ tag = self._get_tag_from_specification(tag_spec)