Skip to content

Commit

Permalink
Merge pull request #962 from szoupanos/fix_for_960
Browse files Browse the repository at this point in the history
Fix for #960
  • Loading branch information
lekah authored Nov 29, 2017
2 parents 1d3b12e + a01bcbe commit 0a3fca1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
11 changes: 4 additions & 7 deletions aiida/backends/sqlalchemy/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,14 @@ def set_script_md5(self, md5):
self.script_md5 = md5
self.save()

# def add_data(self, dict, d_type):
# for k in dict.keys():
# p, create = self.data.get_or_create(name=k, data_type=d_type)
# p.set_value(dict[k])

def add_data(self, dict, d_type):
for k in dict.keys():
p, create = self._get_or_create_data(name=k, data_type=d_type)
p.set_value(dict[k])

def _get_or_create_data(self, name, data_type):
match_data = {name: _ for _ in self.data if _.name == name}
match_data = {name: _ for _ in self.data if _.name == name
and _.data_type == data_type}

if not match_data: # create case
dbdata = DbWorkflowData(parent_id=self.id, name=name, data_type=data_type)
Expand Down Expand Up @@ -250,7 +246,8 @@ def set_value(self, arg):
try:
if isinstance(arg, Node) or issubclass(arg.__class__, Node):
if arg.pk is None:
raise ValueError("Cannot add an unstored node as an attribute of a Workflow!")
raise ValueError("Cannot add an unstored node as an "
"attribute of a Workflow!")
sess = get_scoped_session()
self.aiida_obj = sess.merge(arg.dbnode, load=True)
self.value_type = wf_data_value_types.AIIDA
Expand Down
31 changes: 31 additions & 0 deletions aiida/backends/tests/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,37 @@ def test_failing_calc_in_wf(self):
if handler:
handler.setLevel(original_level)

def test_result_parameter_name_colision(self):
"""
This test checks that the the workflow parameters and results do not
collide. This was a problem in SQLA (Issue #960) but a test for both
backends is added (for completeness).
"""
# Creating a simple workflow & storing it
wf = WFTestEmpty()
wf.store()

# Set some parameters
params = {'band_calculation_set': 2,
'codename': 'pw-5.2.0',
'pseudo_family': 'SSSP_v0.7_eff_PBE'}
wf.set_params(params)

# Add some results that their names collide with the parameter names
wf.add_result('structure', 'test_string_1')
wf.add_result('codename', 'test_string_2')

# Check that we have the correct results
self.assertDictEqual(
{'structure': 'test_string_1', 'codename': 'test_string_2'},
wf.get_results(), "The workflow results are not the expected "
"ones.")

# Check that we have the correct parameters
self.assertDictEqual(params, wf.get_parameters(),
"The workflow parameters are not the expected "
"ones.")

def tearDown(self):
"""
Cleaning the database after each test. Since I don't
Expand Down

0 comments on commit 0a3fca1

Please sign in to comment.