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

'input' and 'data' should be reserved identifiers #2600

Closed
jpeach opened this issue Aug 3, 2020 · 2 comments · Fixed by #4301
Closed

'input' and 'data' should be reserved identifiers #2600

jpeach opened this issue Aug 3, 2020 · 2 comments · Fixed by #4301
Assignees

Comments

@jpeach
Copy link
Contributor

jpeach commented Aug 3, 2020

Expected Behavior

If I define a function whose name is data, the compiler should probably emit an error that directly specifies that's not going to work.

Actual Behavior

I ended up with this compiler error:

 rego_type_error: undefined function data.contour.configmap.data.contour.configmap.data.contour.resources.get

Steps to Reproduce the Problem

package contour.resources.configmap

import  data.contour.resources

data(name) = obj {
  config := resources.get("configmaps", name)
  obj := object.get(config, "data", {})
}

Additional Info

I'm using OPA v0.19.2 as a library.

@tsandall
Copy link
Member

tsandall commented Aug 4, 2020

We currently allow policies to override built-in functions as well as the input and data global variables.

input overriding can actually be quite useful during development/debug cycles if you want to quickly replace the value of input inside of a package for test purposes. data overriding is less useful because you're unlikely to replace the value of data correctly.

In this case, I'm assuming the import data.countour.resources was resolved to the local data function (so the reference data.contour.resources became data.contour.resources.configmap.data.contour.resources like in the error message.) I would have expected imports to be fully qualified so it's arguable this is a bug and should be fixed. That said, I'm not sure how I feel about disallowing overriding entirely.

cc @timothyhinrichs WDYT?

@tsandall tsandall added the bug label Aug 4, 2020
@tsandall tsandall self-assigned this Aug 4, 2020
@timothyhinrichs
Copy link
Member

Thanks for the reminder @tsandall that supporting overriding for functions is necessary to ensure backwards compatibility of policies. I could see prohibiting overriding data (especially) and input (possibly). Tooling around the playground, vscode plugin, etc. has improved to the point where I don't personally use input overriding anymore for debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants