-
Notifications
You must be signed in to change notification settings - Fork 10
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
patch command will not add values to null key #80
Comments
Another option for the user that currently works is specifying an empty object with brackets
|
Current behaviour is correct imo. JSON makes an explicit distinction between a NULL value and no value (absent). Since patch tries to add values to an object, and NULL is not an object, it refuses to add it. Which is correct. |
Disagree based on user experience. From the perspective of a "patch" operation the user doesn't care if it's null or empty, and they are providing values to apply to the target key (which exists). There is no technical reason to prevent this, and it makes more sense from the user's perspective. That JSON nuance isn't relevant to the user. |
So the desired behaviour is that if a key exists, but is not an object, we drop the value, replace it with an empty object (or array if that's what we're patching), and then apply the patch? |
I assume it's possible to determine if an existing key's value is either an object, null, or an array? If so, and if a key is null, and the user is expressing the patching of object values to it, why not allow them to do that? If they are attempting to patch an object to an existing Array, then an error seems appropriate. Same with an array to an existing object. The upshot is, it seems very likely to me that a key will be defined with objects as a placeholder for values applied later in a pipeline. The placeholder expresses something in the "code", which is "values to be applied later". |
correct
That would effectively mean replacing a Referring to my previous comment; only for If If overwriting any non-matching type, then it would at least be consistent and less surprising, but it would also make it easier to overwrite other entries as well if one doesn't specifify the selector well enough.
Current behaviour is defined as: patching object-fields to something that is not an object, simply will be ignored, no errors. Same for adding array entries to something that is not an array.
Shouldn't those place holders then have the target type in the first place? eg. an object Either way (nulls or all non-matching types) is going to be a breaking change. Maybe we can add a flag to specify that non-matching types should be replaced? @mheap wdyt? |
Is there a way to detect the difference between explicit |
I'm still interested in the answer, but I just realised that this wouldn't work due to the |
I think
I agree that "changing the type" may be unexpected, but I would expect this to work like so: If the value of a key is null, define it with the provided value. If the provided value is null, set the target key's value to null. If a key has a value and provided type does not match (except
The user, by nature of running the "last" patch command, is expressing what they want the key's value to be. If they want it to be |
Strong agree - we should default to fail fast where we can
In general, yes. In JSON patch, it has a semantic meaning (remove the existing value). Given the user needs to add an empty If I were building this feature, I'd expect the following:
|
Agree. It's best practice to convey the type info this way (as a general programming practice, eg. if a function returns an array, but there is nothing to return, return an empty one instead of null, to save the caller an additional type-check).
Requesting the user to define the placeholder as the proper type (eg.
I do not think that is helpful in this case; The patch operations explicitly defined the patch to be on an array or an object. So the user clearly expresses their intent to patch only those types. So it is safe to ignore other values. Consider the following json: {
"filter_by": {
"tags": true,
"name": false
},
"data": {
"key1": {
"tags": { "hello": "world" }
},
"key2":{
"tags": { "hello": "world" }
},
"tags": { "hello": "world" }
},
"tags": { "hello": "world" }
} Currently a recursive patch for all If we throw a hard error on this then for a user to work around this would be quite cumbersome I think. Especially because of the dynamic data we're dealing with. Any custom plugin can introduce a field that has a name collision with an existing Kong field. |
That's a good example. Users can work around it by specifying more specific selectors. On balance, I think raising an error is the better experience for 90% of users. |
Trying to catch up on this issue. My summary and comments:
To decide between these options I think about whether there would be cases where a partial patch application success would be desirable or not. On the one hand the warning approach is the least 'breaking' from the current behavior: pipelines still complete and the output files are still the same, but it does potentially leave someone with an output that may be incomplete in someway. On the other hand a hard error would force people to really inspect the output and fix the problem in their pipeline. I tend to come down on changing this to a hard error. Does this summary reflect everyone else's understanding? |
In a pipeline you do not know what "comes before", so my point is if something should be null, you should set it to null as you can't assume from earlier in a federated pipeline. |
I don't believe there is value in continuing this debate under this current ticket. Despite my view that we could initialize a null object in these cases, the user can accomplish what is needed by explicitly initializing a key as an empty object as the placeholder. Additionally, a user can overwrite or change any type of object as they see fit by selecting the parent. However, there is a pattern that has emerged from the discussion that the tool will fail silently (ignore given configurations and patches), and I consider that a bug and should be addressed independently. Captured here: #108 |
Take this input config (
input.yaml
)And this patch file (
patch.yaml
):Ran as:
Results in:
If I change
input.yaml
to:The result will be:
The
patch
command should be able to create a new key in an existing null valued key.The text was updated successfully, but these errors were encountered: