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

Issue with applying diff with CompatibilityFlags.ALLOW_MISSING_TARGET_OBJECT_ON_REPLACE #163

Open
tanmayvijay opened this issue Jan 4, 2023 · 0 comments

Comments

@tanmayvijay
Copy link

When we have a diff specifying a replace operation on a path and one of the tokens in the path is not present in the target json, we get an error:
[REPLACE operation] Missing field "path_token" at /path_token_x/path_token_y.

This case is handled in replace operation with CompatibilityFlags.ALLOW_MISSING_TARGET_OBJECT_ON_REPLACE. Problem is, every operation runs an evaluate() call on target json, which checks if all the tokens from root to the parent of token to be replaced are present or not, and if any of them is missing we get this error. So, this compatibility check effectively works only if the target field is missing and not if some ancestor token is missing.

This applies to all operations.

Is this done on purpose? If yes, why can't we have a compatibility check for all tokens on the path?

Can we have a fix for this? I can create a PR if this is not being already worked on.

Expected Behaviour

Have a compatibility flag to allow for missing tokens on entire path.

Actual Behaviour

Currently, we only allow target values to be missing and if any token on the path is missing, we fail with above error. Not just in replace operation, but in all operations.

Steps to Reproduce the Problem

Try applying given diff on the given target Json:

diff: [{"op":"replace","path":"/t1/t2/t3/t4","value":"new_value"}]

target: { "t1": { "t2": { } } }

Error expected: [REPLACE Operation] Missing field "t3" at /t1/t2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant