Skip to content

Invalid yaml workflows due to PyYaml's default 80-character width limit #1504

@jaseemabid

Description

@jaseemabid

1. This bug can be reproduced using pure Argo YAML

2. I have searched for existing issues

  • Yes

3. This bug occurs in Hera when...

  • exporting to YAML
  • submitting to Argo
  • running on Argo with the Hera runner
  • other:

Bug report

Describe the bug

Hera's to_yaml() method uses PyYAML's default 80-character line width, which breaks long template expressions across multiple lines, making them syntactically invalid for Argo Workflows.

To Reproduce

  from hera.workflows import WorkflowTemplate
  from hera.workflows import models as m

  # Create a workflow with a long template expression
  wt = WorkflowTemplate(
      name="test-yaml-wrapping",
      workflow_metadata=m.WorkflowMetadata(
          annotations={
              "workflows.argoproj.io/description": "ref={{= sprig.trunc(7, workflow.parameters.gh-ref) }}, push={{ workflow.parameters.push }}"
          }
      )
  )

  print("Current output (breaks template expression):")
  print(wt.to_yaml())

  print("\nWith width=160 (keeps template expression intact):")
  print(wt.to_yaml(width=160))

Expected behavior
Template expressions should remain on a single line to maintain their syntactic validity:

  workflowMetadata:
    annotations:
      workflows.argoproj.io/description: ref={{= sprig.trunc(7, workflow.parameters.gh-ref) }}, push={{ workflow.parameters.push }}

Actual behavior

Template expressions are broken across lines, making them invalid:

  workflowMetadata:
    annotations:
      workflows.argoproj.io/description: ref={{= sprig.trunc(7, workflow.parameters.gh-ref)
        }}, push={{ workflow.parameters.push }}

Additional context

We could set a reasonable default width (like 160) to fix the issue? Would you like me to create a PR @elliotgunton?

  def dump(*args, **kwargs) -> str:
      # Set some default options if not provided by the user
      kwargs.setdefault("default_flow_style", False)
      kwargs.setdefault("sort_keys", False)
      kwargs.setdefault("width", 160)  # 👈🏼 👈🏼 👈🏼
      return _yaml.dump(*args, **kwargs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions