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

Unhandled None in jsonpath.Slice #82

Open
jacobbogdanov opened this issue Jun 24, 2020 · 2 comments
Open

Unhandled None in jsonpath.Slice #82

jacobbogdanov opened this issue Jun 24, 2020 · 2 comments

Comments

@jacobbogdanov
Copy link

jacobbogdanov commented Jun 24, 2020

When specifying a json path that contains a [*], if the value is None then a TypeError is raises.

Expected behavior

No exception is raised, and an empty result set is returned.

Minimal reproduction of the issue

>>> import jsonpath_rw
>>> d = {"key": None}
>>> p = jsonpath_rw.parse('$.key.[*].value')
>>> p.find(d)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    p.find(d)
  File "lib/python3.6/site-packages/jsonpath_rw/jsonpath.py",
 line 226, in find
    for subdata in self.left.find(datum)
  File "lib/python3.6/site-packages/jsonpath_rw/jsonpath.py",
 line 226, in find
    for subdata in self.left.find(datum)
  File "lib/python3.6/site-packages/jsonpath_rw/jsonpath.py",
 line 228, in <listcomp>
    for submatch in self.right.find(subdata)]
  File "lib/python3.6/site-packages/jsonpath_rw/jsonpath.py",
 line 494, in find
    return [DatumInContext(datum.value[i], path=Index(i), context=datum) for i in xrange(0, len(datum.value)
)]
TypeError: object of type 'NoneType' has no len()

Version

tested against python3.6 and jsonpath_rw==1.4.0

edit: this seems to be fixed by #77, but I can't find the corresponding issue

@paalbra
Copy link

paalbra commented Mar 16, 2021

I'm experiencing the same issue. Pip installed from github/master. Python 3.9.1.

Possibly second problem (that might be related/close)?:

>>> jsonpath_rw.parse("list[*]").find({"list": None})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/.local/lib/python3.9/site-packages/jsonpath_rw/jsonpath.py", line 229, in find
    return [submatch
  File "/root/.local/lib/python3.9/site-packages/jsonpath_rw/jsonpath.py", line 232, in <listcomp>
    for submatch in self.right.find(subdata)]
  File "/root/.local/lib/python3.9/site-packages/jsonpath_rw/jsonpath.py", line 546, in find
    return [DatumInContext(datum.value[i], path=Index(i), context=datum) for i in xrange(0, len(datum.value))]
TypeError: object of type 'NoneType' has no len()
>>> jsonpath_rw.parse("list[*]").find({"list": 1})
[DatumInContext(value=1, path=<jsonpath_rw.jsonpath.Index object at 0x7f1cb1d6a3d0>, context=DatumInContext(value=[1], path=Fields('list'), context=DatumInContext(value={'list': 1}, path=This(), context=None)))]
>>> jsonpath_rw.parse("list[*]").find({"list": "foo"})
[DatumInContext(value='foo', path=<jsonpath_rw.jsonpath.Index object at 0x7f17f674d1f0>, context=DatumInContext(value=['foo'], path=Fields('list'), context=DatumInContext(value={'list': 'foo'}, path=This(), context=None)))]

The array-syntax shouldn't match an int or string (nor other types)?

This issue (and the referenced PR) is fairly old though. Is this library alive and well?

@paalbra
Copy link

paalbra commented Mar 16, 2021

This issue (and the referenced PR) is fairly old though. Is this library alive and well?

Discussion regarding the health of this library #73

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