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

Bug: Remove /array/- raises TypeError #133

Open
Ventilateur opened this issue Apr 2, 2021 · 5 comments
Open

Bug: Remove /array/- raises TypeError #133

Ventilateur opened this issue Apr 2, 2021 · 5 comments

Comments

@Ventilateur
Copy link

Version: 1.32
Python version: 3.8

Description
Removing array element with dash notation raises an unexpected TypeError. Like so: {'op': 'remove', 'path': '/vals/-'}.
I understand that the dash points to the end of array, but not the last element? Even so, if the syntax is invalid, I think it should raise a JsonPatchException or JsonPointerException.

Step to reproduce

jsonpatch.JsonPatch([
        {'op': 'remove', 'path': '/vals/-'}
    ]).apply({
        'vals': [1, 2, 3]
    })

Stack trace

File "\lib\site-packages\jsonpatch.py", line 669, in apply
    obj = operation.apply(obj)
  File "\lib\site-packages\jsonpatch.py", line 238, in apply
    del subobj[part]
TypeError: list indices must be integers or slices, not str
@stefankoegl
Copy link
Owner

Thanks for the report. I think your suggestion makes a lot of sense.

Would you be interested in preparing a pull request?

@Ventilateur
Copy link
Author

Ok, I will find some time to do it. So according to this section, I think it make sense to raise a JsonPointerException in this case. What do you think?

@stefankoegl
Copy link
Owner

Agreed - makes sense

@Ventilateur
Copy link
Author

FYI I made a PR, can you check please?

@stefankoegl
Copy link
Owner

Looks good! I’ll merge and include it in the next release. Thanks!

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

2 participants