spiff icon indicating copy to clipboard operation
spiff copied to clipboard

Spiff expression in "or logic" ("||") is not working correctly in v1.7.0-beta-4

Open DimitarVoynov opened this issue 1 year ago • 3 comments
trafficstars

Hi @mandelsoft,

we identified that due to the following change: https://github.com/mandelsoft/spiff/commit/f5332183feaf4bbdaa85934b0397bcb6caf737a4 spiff is not working correctly with the following set of yaml files:

1) context-template.yml

...
terraform:
  db:
    name: (( merge || ( terraform.properties.inst_name "db" ) ))
    user: (( merge ))
    password: (( merge ))

  databases:
    - name: (( terraform.db.name ))
      user: (( terraform.db.user ))
      password: (( terraform.db.password ))
    - <<<: (( merge || ~ ))

  properties:
    <<<: (( merge ))
    inst_name: (( merge ))
.....
  1. config.yml
---

credentials: (( merge ))

terraform:
  properties:
    inst_name: apps

  db:
    user: (( credentials.rds.appsdb.user ))
    password: ((!appsdb_password))

  databases:
    - name: availability
      password: ((!availability_password))
      user: availability_admin
    - name: xsuaa
      password: ((!xsuaa_password))
      user: xsuaa_admin

  1. credentials.yml
---
credentials:
  rds:
    appsdb:
      user: admin

With spiff versions before v1.7.0-beta-4 the line:

name: (( merge || ( terraform.properties.inst_name "db" ) ))

correctly works - i.e. the value after "||" gets resolved to value "appsdb" - thus resulting in a correct merged context.yml file:

terraform:
  databases:
    - name: availability
      password: ((!availability_password))
      user: availability_admin
    - name: xsuaa
      password: ((!xsuaa_password))
      user: xsuaa_admin
    - name: appsdb
      password: ((!appsdb_password))
      user: admin

while starting with version v1.7.0-beta-4 of spiff - the merged yml is wrong:

terraform:
  databases:
    - name: availability
      password: ((!availability_password))
      user: availability_admin
    - name: xsuaa
      password: ((!xsuaa_password))
      user: xsuaa_admin
    - name: xsuaa
      password: ((!xsuaa_password))
      user: xsuaa_admin

To us this looks like a bug or at least - a change that is not backward compatible. Can you please have a look/fix it?

Thanks, Dimitar

DimitarVoynov avatar Jul 15 '24 09:07 DimitarVoynov

Sorry for the delay, I was very busy with other things...

Hmm, the problem is even worse, the list merge does not work anymore, if the base list has more than one entry.

The minimal scenario seems to be:

  effname: (( properties.inst_name "db" ))

  databases:
    - name: (( effname ))
    - <<<: (( merge || ~ ))

  properties:
    <<<: (( merge ))
    inst_name: apps
 properties: 
    inst_name: apps
  
  databases:
    - name: first
    - name: second

mandelsoft avatar Sep 08 '24 12:09 mandelsoft

This looks very difficult, basically it formerly worked only by accident. There is a severe problem even in earlier releases which just reveals by the mentioned change in your scenario,

mandelsoft avatar Sep 08 '24 15:09 mandelsoft

Hi @DimitarVoynov, could you test the branch dev for your scenarios, please.

mandelsoft avatar Sep 08 '24 17:09 mandelsoft

Hi @mandelsoft,

building spiff from the dev branch and testing - we didn't face the reported issue in v1.7.0-beta-4. Are you going to make a new release with the fix so it can be consumable?

Thanks, Dimitar

DimitarVoynov avatar Oct 03 '24 09:10 DimitarVoynov

solved with https://github.com/mandelsoft/spiff/releases/tag/v1.7.0-beta-6

mandelsoft avatar Oct 14 '24 16:10 mandelsoft