diff --git a/solar/dblayer/solar_models.py b/solar/dblayer/solar_models.py index 724c940b..73e1dbd8 100644 --- a/solar/dblayer/solar_models.py +++ b/solar/dblayer/solar_models.py @@ -174,7 +174,13 @@ class InputsFieldWrp(IndexFieldWrp): if '|' in my_val: my_val, my_tag = my_val.split('|', 1) else: - my_tag = other_resource.name + if real_my_type == InputTypes.hash: + # when single dict then set shared hash for all resources + # TODO: (jnowak) maybe we should remove tags completely + # in this and only this case + my_tag = '_single' + else: + my_tag = other_resource.name my_inp_name = my_key other_ind_val = '{}|{}|{}|{}|{}|{}'.format( other_resource.key, other_inp_name, my_resource.key, @@ -223,7 +229,12 @@ class InputsFieldWrp(IndexFieldWrp): if '|' in my_val: my_val, my_tag = my_val.split('|', 1) else: - my_tag = other_resource.name + # when single dict then set shared hash for all resources + # TODO: (jnowak) maybe we should remove tags completely there + if my_type == InputTypes.hash: + my_tag = '_single' + else: + my_tag = other_resource.name types_mapping = '|{}_{}'.format(my_type.value, other_type.value) my_ind_name = '{}_recv_bin'.format(self.fname) my_ind_val = '{}|{}|{}|{}|{}|{}'.format(my_resource.key, my_key, @@ -453,17 +464,18 @@ class InputsFieldWrp(IndexFieldWrp): emitter_inp, other) elif splen == 7: # partial - (_, _, emitter_key, emitter_inp, - my_tag, my_val, mapping_type) = splitted - cres = Resource.get(emitter_key).inputs._get_field_val( - emitter_inp, other) - res = {my_val: cres} + res = {} my_resource = self._instance my_resource_value = my_resource.inputs._get_raw_field_val( input_name) if my_resource_value: for my_val, cres in my_resource_value.iteritems(): res[my_val] = cres + (_, _, emitter_key, emitter_inp, + my_tag, my_val, mapping_type) = splitted + cres = Resource.get(emitter_key).inputs._get_field_val( + emitter_inp, other) + res[my_val] = cres else: raise Exception("Not supported splen %s", splen) else: diff --git a/solar/dblayer/test/test_real.py b/solar/dblayer/test/test_real.py index 7cf58f0c..750de8d7 100644 --- a/solar/dblayer/test/test_real.py +++ b/solar/dblayer/test/test_real.py @@ -316,6 +316,51 @@ def test_simple_to_dict_inputs(rk): assert r2.inputs['input']['input2'] == 15 +def test_simple_to_dict_inputs_without_tag_single_key(rk): + k1 = next(rk) + k2 = next(rk) + + r1 = create_resource(k1, {'name': 'first', + 'inputs': {'input1': 10, + 'input2': 15}}) + r2 = create_resource(k2, {'name': 'second', + 'inputs': {'input': {'input1': None, + 'input2': None}}}) + + r1.connect(r2, {'input1': 'input:input1'}) + + r1.save() + r2.save() + + assert r2.inputs['input']['input1'] == 10 + + +def test_simple_to_dict_inputs_without_tag(rk): + k1 = next(rk) + k2 = next(rk) + k3 = next(rk) + + r1 = create_resource(k1, {'name': 'first', + 'inputs': {'input1': 10, + 'input2': 15}}) + r3 = create_resource(k3, {'name': 'third', + 'inputs': {'input1': 110, + 'input2': 115}}) + r2 = create_resource(k2, {'name': 'second', + 'inputs': {'input': {'input1': None, + 'input2': None}}}) + + r1.connect(r2, {'input1': 'input:input1'}) + r3.connect(r2, {'input2': 'input:input2'}) + + r1.save() + r2.save() + r3.save() + + assert r2.inputs['input']['input1'] == 10 + assert r2.inputs['input']['input2'] == 115 + + def test_simple_to_dict_inputs_with_tag(rk): k1 = next(rk) k2 = next(rk)