From 3dd0bc65ffb7e8fe02b9395953e8d01440623a76 Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Tue, 16 Jan 2018 20:38:46 +0100 Subject: [PATCH 1/2] Check that calculation type strings start with 'calculation.job.' prefix --- .../general/calculation/job/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/aiida/orm/implementation/general/calculation/job/__init__.py b/aiida/orm/implementation/general/calculation/job/__init__.py index e1dbb09c3b..17625959d1 100644 --- a/aiida/orm/implementation/general/calculation/job/__init__.py +++ b/aiida/orm/implementation/general/calculation/job/__init__.py @@ -1089,9 +1089,14 @@ def _get_calculation_info_row(cls, res, projections, times_since=None): d = copy.deepcopy(res) try: - d['calculation']['type'] = from_type_to_pluginclassname( - d['calculation']['type'] - ).rsplit(".", 1)[0].lstrip('calculation.job.') + prefix = 'calculation.job.' + calculation_type = d['calculation']['type'] + calculation_class = from_type_to_pluginclassname(calculation_type) + module, class_name = calculation_class.rsplit('.', 1) + + assert(module.startswith(prefix)) + + d['calculation']['type'] = module[len(prefix):] except KeyError: pass for proj in ('ctime', 'mtime'): From ce866dbb52c16f0eca3b4feec468df31c080e8cd Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Wed, 17 Jan 2018 12:32:20 +0100 Subject: [PATCH 2/2] Special check for 'calculation.job.JobCalculation' in _get_calculation_info_row Calculations of the base class JobCalculation will have the class name string 'calculation.job.JobCalculation'. In the _get_calculation_info_row method the module will therefore be, after the rsplit on the class name, like calculation.job this does not include a period on the end like non base modules would have. In this exceptional case, the calculation type that is to be returned should simply be the 'calculation.job' base module --- .../general/calculation/job/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/aiida/orm/implementation/general/calculation/job/__init__.py b/aiida/orm/implementation/general/calculation/job/__init__.py index 17625959d1..2aa60c3d6a 100644 --- a/aiida/orm/implementation/general/calculation/job/__init__.py +++ b/aiida/orm/implementation/general/calculation/job/__init__.py @@ -1094,9 +1094,14 @@ def _get_calculation_info_row(cls, res, projections, times_since=None): calculation_class = from_type_to_pluginclassname(calculation_type) module, class_name = calculation_class.rsplit('.', 1) - assert(module.startswith(prefix)) - - d['calculation']['type'] = module[len(prefix):] + # For the base class 'calculation.job.JobCalculation' the module at this point equals 'calculation.job' + # For this case we should simply set the type to the base module calculation.job. Otherwise we need + # to strip the prefix to get the proper sub module + if module == prefix.rstrip('.'): + d['calculation']['type'] = module[len(prefix):] + else: + assert module.startswith(prefix), "module '{}' does not start with '{}'".format(module, prefix) + d['calculation']['type'] = module[len(prefix):] except KeyError: pass for proj in ('ctime', 'mtime'):