Logical error in if statements results in KeyError
Closed this issue · 4 comments
Hi! I think I found some bugs.
Please have a look at the following if statements:
The two conditions contradict each other respectively. If the first is true, the second one won’t and will fail with a KeyError!
Steps to reproduce:
schema = {}
if "schema" not in schema and "fields" not in schema['schema']:
raise RuntimeError('something went wrong...')
response_json = {}
if "response" not in response_json and "numFound" not in response_json['response']:
raise RuntimeError('something went wrong...')
The issue could be solved by changing and
to or
...
@herreio can you give an example (e.g. the solr (JSON) response that will be evaluated), where it fails with a KeyError?
In general, feel free to open a pull request with your intended solution ;)
Dear @zazi, thanks for the quick reply! Please have a look at the two examples I gave above to reproduce the error. In both examples the first part of the if conditions is true ('key' not in dict), so the second part is evaluated, in which exactly the key is used for which it was previously determined that it does not exist. There you have the KeyEror! Anyway, I'm happy to make a pull request.