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

cue/go: cue.Value.Subsume appears to ignore cue.Raw() #1470

Closed
sdboyer opened this issue Jan 14, 2022 · 2 comments
Closed

cue/go: cue.Value.Subsume appears to ignore cue.Raw() #1470

sdboyer opened this issue Jan 14, 2022 · 2 comments

Comments

@sdboyer
Copy link

sdboyer commented Jan 14, 2022

What version of CUE are you using (cue version)?

$ cue version v0.4.1

Does this issue reproduce with the latest release?

Yes

What did you do?

Checked for subsumption using cue.Raw() between two values that differ only by a field that has a default marker.

package main

import (
	"fmt"

	"cuelang.org/go/cue"
	"cuelang.org/go/cue/cuecontext"
)

const defaultsubsume = `
#one: {
	init: string
}
#two: {
	init: string
	withDefault: *"foo" | "bar" | "baz"
}
`

func main() {
	ctx := cuecontext.New()
	v := ctx.CompileString(defaultsubsume)

	one := v.LookupPath(cue.ParsePath("#one"))
	two := v.LookupPath(cue.ParsePath("#two"))
	fmt.Println(two.Subsume(one, cue.Raw(), cue.Schema()))
}

What did you expect to see?

That #two subsumes #one, when considering defaults (as the cue.Raw() docs indicate).

<nil>

What did you see instead?

required field is optional in subsumed value: withDefault (and 1 more errors)
@sdboyer sdboyer added NeedsInvestigation Triage Requires triage/attention labels Jan 14, 2022
@mpvl
Copy link
Member

mpvl commented Jan 15, 2022

one is more broad than two. So two.Subsume(one) will not succeed under any circumstances.

@mpvl mpvl added NeedsVerification and removed NeedsInvestigation Triage Requires triage/attention labels Jan 15, 2022
@sdboyer
Copy link
Author

sdboyer commented Jan 17, 2022

Ah! OK, that simplifies things. It also explains why i've found some of the discussion around required fields, e.g. #822, confusing - my mental model has been off. FWIW, i think i was thrown off by this wording in the docs:

Use the Raw option to do a low-level subsumption, taking defaults into account.

In retrospect, i realize that i made an incorrect inference here - that doc refers to whether defaults on two existing fields are considered in subsumption, not on whether a default in the subsumer obviates the need for field existence in the instance. I thought it referred to both; that it refers only to the former is certainly simpler, and i'm delighted to have clarified a previously fuzzy area of my CUE mental model.

It's relatively simple to adapt Thema to this, so i can pivot - the simple answer is to just change existing guidance/thinking existing that defaults are sufficient to have the addition of a required field be considered backwards compatible.

All that said, i think part of the reason i made this erroneous inference in the first place was because i've narrowed my thinking to the one use case: authoring schema in CUE, but working with them primarily from other languages, and therefore using concrete objects. In that context, conflating these ideas makes sense - once an object has 'left' CUE, where the value came from doesn't really matter anymore. However, this starts veering into trickier territory about openness and closedness that i haven't figured out how to discuss yet - and is out of scope for this issue, as Subsume() is clearly behaving as expected.

Thanks!

@sdboyer sdboyer closed this as completed Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants