-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Duplicate JSON files provided to OPA could be dealt with more gracefully #2983
Comments
@anderseknert just saw you added the "good first issue" label. Do you think this is something I can take can fix? |
Hi @faraway, I am currently working on this |
This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. |
This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. |
This came up again today, when someone ran something like |
This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. |
I am seeing this error when trying to do
I do not have duplicated files inside the src folder and I started getting this error when I added a 2nd schema json file to my schema folder. Any ideas? And if no one is currently investigating this issue, I can take care of it. |
OPA merges all data it encounters according to its document model. You don't need to have duplicate files for this error to be displayed — just data that exists at the same path in two different JSON documents. I.e. foo.json {"foo": 1} bar.json {"foo": 2} Would be a conflict, as foo will be merged into the same document from two different sources. |
Thanks for the response. I added a new schema file and its contents is just a new json object, so no same key was being used. I even made sure to have a different "id" for the schema, no difference. The Doc page about Schema give us example of using multiple schema files and even provides a repo example here. I just tried running
Maybe we have an issue merging schema objects? PS: Funny that I get the error (on my code, not the k8s above) during tests (which I do not even need the schema) and when I do PS2: Yes, if I run |
I believe some attribute is merged with a conflict :) If you can create a minimal repo to reproduce I'd be happy to take a look. |
There you go: https://github.com/renatosc/opa-merge-error |
Thanks Renato! That is a conflict, as both of your schemas contain the same keys at the same level of the document. You'd either need to put each under it's own top-level key, like: {
"schema1": { ... }
} Or use a directory structure where each file is in its own directory, and treat the topmost directory as a bundle (i.e. |
Hi @anderseknert, thanks for checking it out. I tried your suggestion of adding a key (like as "schema1") before the current schema json object and although it fixes the merge error it appears to make the schema validation to not work properly. I updated the repo by updating the policy1_schema.json to have a "schema1" key as you suggested. I also changed the schema to expect a So, by running
I am now getting no error back when I should in fact be receiving an error (since schema is expecting If I remove that "schema1" key added the schema file and run the command above, I get the schema validation error correctly. Any ideas? |
Ah okay, I think I see what's going on here. OPA merges all documents that are included for policy evaluation — i.e. all documents that contribute to the data document. The documents loaded using the |
Yes, which goes to my point that maybe we could have a bug on |
Not sure what the bug would be though. If you run Rather than running
And then you'll be able to run If you'd like to contribute, perhaps adding the |
I think adding a Right now I was able to make it work by calling |
Agreed, that'd be a nice addition. @johanfylling do you remember where this was discussed in the past? |
@anderseknert , this is probably the issue you're thinking of: #5430 |
Thanks @johanfylling! That was it, yes. @renatosc if you'd like to work on that, I'd be happy to create an issue. |
@anderseknert Yes, I can work on that. |
There you go :) #5923 |
This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue. |
If a JSON file is provided more than once when starting OPA, a merge error is thrown. This came up on Slack when a user mistakenly used something like
opa test . data.json
and got a cryptic merge error as a result.Expected Behavior
OPA should be able to either 1) filter out duplicates from the list of provided files or 2) give a more specific error message if duplicates are found.
Actual Behavior
1 error occurred during loading: data.json: merge error
Steps to Reproduce the Problem
The text was updated successfully, but these errors were encountered: