slub/solr-fstats

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:

  1. solr_fstats/solr_fstats.py#L61
  2. solr_fstats/solr_fstats.py#L99
  3. solr_fstats/solr_fstats.py#L112

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...

zazi commented

@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.

zazi commented

Got it (sorry for the "long line" - it was a bit too hot for me yesterday :) ).
Thanks a lot for the pull request @herreio.
Unfortunately, I have no write access to this repository anymore. Hence, someone from the SLUB team need to handle the merge (maybe @jnauber can do it ;) ).

Thanks @herreio, i merged your pull request.