Skip to content

Commit

Permalink
Do not keep empty Node actions in serialized output
Browse files Browse the repository at this point in the history
There's no need to have the optional empty list there if the input maybe wasn't there in the first place.
  • Loading branch information
akx committed Nov 4, 2021
1 parent 7743b5c commit 641bc3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,11 @@ def test_action_pipeline(pipeline_config: Config):
'then': ['noop'],
'when': ['node-complete', 'node-starting'],
}


def test_empty_actions_not_serialized(pipeline_config: Config):
pl = pipeline_config.pipelines["Last action pipeline"]
train_node = pl.get_node_by(name='train')
assert train_node
train_node.actions.clear()
assert 'actions' not in train_node.serialize()
2 changes: 2 additions & 0 deletions valohai_yaml/objs/pipelines/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def parse_qualifying(cls, data: dict) -> 'Node':
def serialize(self) -> dict:
ser = super().serialize()
ser['type'] = self.type
if not ser.get('actions'):
ser.pop('actions', None)
return ser

def lint(self, lint_result: LintResult, context: dict) -> None:
Expand Down

0 comments on commit 641bc3b

Please sign in to comment.