Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff display for string values with YAML contents displays empty objects incorrectly #11799

Closed
lukehoban opened this issue Jan 6, 2023 · 4 comments · Fixed by #11803
Closed
Assignees
Labels
area/cli UX of using the CLI (args, output, logs) kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@lukehoban
Copy link
Member

This program:

package main

import (
	p "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	p.Run(func(ctx *p.Context) error {
		ctx.Export("foo", p.String("foo:\n  bar: {}\n  baz: {}\n"))
		return nil
	})
}

Renders this on pulumi up:

Updating (dev)

View Live: https://app.pulumi.com/lukehoban/goawstest/dev/updates/1

     Type                 Name           Status              
 +   pulumi:pulumi:Stack  goawstest-dev  created (0.00s)     


Outputs:
    foo: (yaml) {
        foo: {
        }
    }


Resources:
    + 1 created

Duration: 2s

Note that it fails to render bar and baz.

If a diff is introduced - like adding a comment to the YAML string - the update diff is also wrong:

package main

import (
	p "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	p.Run(func(ctx *p.Context) error {
		ctx.Export("foo", p.String("#foo\nfoo:\n  bar: {}\n  baz: {}\n"))
		return nil
	})
}
Previewing update (dev)

View Live: https://app.pulumi.com/lukehoban/goawstest/dev/previews/1416a1a4-251b-455f-b794-e597e3351975

     Type                 Name           Plan     
     pulumi:pulumi:Stack  goawstest-dev           


Outputs:
  ~ foo: (yaml) {
        foo: {
        }
    }

Resources:
    1 unchanged

Note that:

  1. bar and baz are still missing
  2. The comment that was introduced is not rendered in the diff
  3. Pulumi shows a ~ indicating a diff, but not diff in the object
@lukehoban lukehoban added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Jan 6, 2023
@dixler dixler added the area/cli UX of using the CLI (args, output, logs) label Jan 6, 2023
@aq17
Copy link
Contributor

aq17 commented Jan 6, 2023

Not rendering bar and baz is currently expected behavior – we don't print empty values (shouldPrintPropertyValue) , but I think it could make sense to remove that?
cc @dixler

@dixler
Copy link
Contributor

dixler commented Jan 6, 2023

@aq17 I did some digging and the behavior of omitting falsey/null/empty values in outputs was introduced in 2017.
53cf9f8

The motivation is the view that outputting empty values will produce a lot of clutter.

Removing it seems reasonable and a quick fix.

@lukehoban
Copy link
Member Author

I think the deeper issue might be point (2).

Fundamentally, it feels like we should never show an empty diff if there is a diff. So my assumption is that the behaviour should be that if there is a diff being reported:
a. if the YAML based rendering does also indicate a diff, show that
b. if the YAML based rendering doesn't indicate a diff, show the text based diff instead

@dixler
Copy link
Contributor

dixler commented Jan 6, 2023

reply race condition. commenting this for future context to link the PRs to this issue.

I've done more digging to address 2 and 3

  1. The comment that was introduced is not rendered in the diff
  2. Pulumi shows a ~ indicating a diff, but not diff in the object

#9380 and #9484 introduced changes that render JSON/YAML parsable strings as objects in diffs.

as such, "foo:\n bar: {}\n baz: {}\n" and "#foo\nfoo:\n bar: {}\n baz: {}\n" are semantically equivalent.

@dixler dixler removed the needs-triage Needs attention from the triage team label Jan 6, 2023
bors bot added a commit that referenced this issue Jan 18, 2023
11803: Display text-based diff if yaml/json diff is semantically equal r=aq17 a=aq17

Fixes #11799 

#9380 and #9484 introduced changes that render JSON/YAML parsable strings as objects in diffs – therefore, examples such as`"foo:\n  bar: {}\n  baz: {}\n"` and `"#foo\nfoo:\n  bar: {}\n  baz: {}\n"` are recognized as equal.

This change causes the display to fall back to showing the text-based diff if the JSON/YAML rendering does not indicate any diff.
It also prints all object keys even if the value is empty, i.e. `bar: {}` or `bar: ""` will be printed instead of `bar` being omitted.

Co-authored-by: aq17 <aqiu@pulumi.com>
bors bot added a commit that referenced this issue Jan 19, 2023
11803: Display text-based diff if yaml/json diff is semantically equal r=aq17 a=aq17

Fixes #11799 

#9380 and #9484 introduced changes that render JSON/YAML parsable strings as objects in diffs – therefore, examples such as`"foo:\n  bar: {}\n  baz: {}\n"` and `"#foo\nfoo:\n  bar: {}\n  baz: {}\n"` are recognized as equal.

This change causes the display to fall back to showing the text-based diff if the JSON/YAML rendering does not indicate any diff.
It also prints all object keys even if the value is empty, i.e. `bar: {}` or `bar: ""` will be printed instead of `bar` being omitted.

Co-authored-by: aq17 <aqiu@pulumi.com>
bors bot added a commit that referenced this issue Jan 19, 2023
11803: Display text-based diff if yaml/json diff is semantically equal r=aq17 a=aq17

Fixes #11799 

#9380 and #9484 introduced changes that render JSON/YAML parsable strings as objects in diffs – therefore, examples such as`"foo:\n  bar: {}\n  baz: {}\n"` and `"#foo\nfoo:\n  bar: {}\n  baz: {}\n"` are recognized as equal.

This change causes the display to fall back to showing the text-based diff if the JSON/YAML rendering does not indicate any diff.
It also prints all object keys even if the value is empty, i.e. `bar: {}` or `bar: ""` will be printed instead of `bar` being omitted.

Co-authored-by: aq17 <aqiu@pulumi.com>
@bors bors bot closed this as completed in 2ef87d8 Jan 19, 2023
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Jan 19, 2023
@AaronFriel AaronFriel added this to the 0.84 milestone Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli UX of using the CLI (args, output, logs) kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants