question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Software Template Array Inputs Not Working As Expected

See original GitHub issue

Expected Behavior

Current Behavior

Consider the following software template:

apiVersion: backstage.io/v1beta2
kind: Template
metadata:
  name: add-addon
  title: Addon
  description: Add addon
spec:
  owner: users
  type: website

  parameters:
    - title: Values
      properties:
       should-be-list:
          title: This is a title and is huge
          description: "this is a description you can't see"
          type: array
          items:
            type: string
  steps:
    - id: fetch-repo
      name: Fetch repo
      action: fetch:plain
      input:
        url: 'https://github.com/asummers/backstage/tree/master'

    - id: fetch-template
      name: Fetch Template
      action: fetch:template
      input:
        url: ./template2
        values:
          list: '{{parameters.should-be-list}}'

    - id: publish
      name: Publish
      action: publish:github:pull-request
      input:
        repoUrl: 'github.com?owner=asummers&repo=backstage'
        title: 'feat: Add addon'
        branchName: 'add-addon'
        description: |
          Add addon

  output:
    links:
      - url: '{{steps.publish.output.remoteUrl}}'
        text: 'Go to PR'

The resulting summary appears as expected with two separate elements and not a combined value Screen Shot 2021-09-07 at 10 08 01 AM

But if we consider the template file

[
{% set comma = joiner() %}
{% for value in values.list -%}
${{ comma() }}${{ value }}
{%- endfor %}
]

[
{% for value in values.list -%}
${{ value }},
{%- endfor %}
]

we get

[

a,.,b,.,c,.,d,:,1,2,3,4,,,w,.,x,.,y,.,z,:,9,8,7,6
]

[
a,.,b,.,c,.,d,:,1,2,3,4,,,w,.,x,.,y,.,z,:,9,8,7,6,
]

This means that the array is being converted to a string somewhere under the hood, which results in arrays disappearing.

Possible Solution

Fix CSS for form and pass along array as is.

Steps to Reproduce

See ## Current Behavior

Context

This makes array forms in software templates impossible as nunjucks does not provide split functionality, to correct the comma joining happening prematurely.

Your Environment

  • NodeJS Version (v12): 14
  • Operating System and Version (e.g. Ubuntu 14.04): Ubuntu 18.04
  • Browser Information: Chrome

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mtlewiscommented, Sep 7, 2021

Probably the first one if that’s alright with you!

1reaction
mtlewiscommented, Sep 7, 2021

Hi @asummers! Thanks so much for the detailed description of the situation you’re facing. The awkwardness of dealing with non-string values in template parameters is something we’re aware of - https://github.com/backstage/backstage/issues/6437 includes a proposal to improve this.

The good news is that it’s possible today to deal with non-string values, as long as they’re convertible to JSON - it’s mentioned in the RFC above, but in short, your template files should receive the list parameter as an array if you convert the parameter to JSON in your template.yaml file like so:

   - id: fetch-template
      name: Fetch Template
      action: fetch:template
      input:
        url: ./template2
        values:
-          list: '{{ parameters.should-be-list }}'
+          list: '{{ json parameters.should-be-list }}'

Hoping this will get you unblocked to use arrays in your templates!

Thanks also for flagging the issue with the styling of array fields. Since this likely requires some code changes to get fixed, can I suggest we create a separate issue to track that part?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is wrong with this template program? - Stack Overflow
You are putting the implementation of your template in a separate file without explicitly instantiating the types you are parameterizing. In ...
Read more >
Type of instance in array does not match expected type
I need to switch between different input systems in the app, and this error is thrown when disabling a GameObject with PlayerInput attached....
Read more >
Help with "Invalid Template error" - Power Platform Community
Solved: Hello. As the title suggests i am having the folowing error " InvalidTemplate . Unable to process template language expressions in.
Read more >
2.4. Inputs — Common Workflow Language User Guide 0.1 ...
However, if you do not provide any input value, then file_format will be evaluated to a null value, which does not match the...
Read more >
10 Most Common Mistakes That PHP Developers Make - Toptal
Common Mistake #1: Leaving dangling array references after foreach loops ... The problem is that, if you're not careful, this can also have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found