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

KeyError thrown when running tests #3169

Closed
reiddraper opened this issue Dec 1, 2021 · 5 comments · Fixed by #3203
Closed

KeyError thrown when running tests #3169

reiddraper opened this issue Dec 1, 2021 · 5 comments · Fixed by #3203
Labels
bug something is clearly wrong here

Comments

@reiddraper
Copy link

Best I can tell, this exception is being thrown from hypothesis itself, and not from my code.

time poetry run ./compare.py                                                                                                            ⏎
You can add @seed(292076761980949346109975285697619484774) to this test to reproduce this failure.
Traceback (most recent call last):
  File "/Users/reiddraper/Desktop/desktop/array-binary-encoding/./compare.py", line 72, in <module>
    test_compare()
  File "/Users/reiddraper/Desktop/desktop/array-binary-encoding/./compare.py", line 63, in test_compare
    @given(pair_of_version_list_with_same_types())
  File "/Users/reiddraper/Library/Caches/pypoetry/virtualenvs/array-binary-encoding-BxhZ887V-py3.9/lib/python3.9/site-packages/hypothesis/core.py", line 1195, in wrapped_test
    raise the_error_hypothesis_found
  File "/Users/reiddraper/Library/Caches/pypoetry/virtualenvs/array-binary-encoding-BxhZ887V-py3.9/lib/python3.9/site-packages/hypothesis/core.py", line 1164, in wrapped_test
    state.run_engine()
  File "/Users/reiddraper/Library/Caches/pypoetry/virtualenvs/array-binary-encoding-BxhZ887V-py3.9/lib/python3.9/site-packages/hypothesis/core.py", line 781, in run_engine
    runner.run()
  File "/Users/reiddraper/Library/Caches/pypoetry/virtualenvs/array-binary-encoding-BxhZ887V-py3.9/lib/python3.9/site-packages/hypothesis/internal/conjecture/engine.py", line 475, in run
    self._run()
  File "/Users/reiddraper/Library/Caches/pypoetry/virtualenvs/array-binary-encoding-BxhZ887V-py3.9/lib/python3.9/site-packages/hypothesis/internal/conjecture/engine.py", line 877, in _run
    self.generate_new_examples()
  File "/Users/reiddraper/Library/Caches/pypoetry/virtualenvs/array-binary-encoding-BxhZ887V-py3.9/lib/python3.9/site-packages/hypothesis/internal/conjecture/engine.py", line 611, in generate_new_examples
    self.__data_cache.pin(zero_data.buffer)
  File "/Users/reiddraper/Library/Caches/pypoetry/virtualenvs/array-binary-encoding-BxhZ887V-py3.9/lib/python3.9/site-packages/hypothesis/internal/cache.py", line 130, in pin
    i = self.keys_to_indices[key]
KeyError: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
poetry run ./compare.py  272.05s user 11.90s system 99% cpu 4:45.48 total
(array-binary-encoding-BxhZ887V-py3.9)

How to reproduce?

Strangely, I'm having trouble reproducing this with the seed(s) printed, but I am able to consistency reproduce without a specific seed provided. Unfortunately it takes 4-5 minutes on my laptop to hit the exception.

git clone git@github.com:reiddraper/array-binary-encoding.git
cd array-binary-encoding
git checkout 0ece9478c4e5def1cc4c8d448fe0ee49e014be64
poetry install
time poetry run ./compare.py # wait about 5 minutes

The code is in https://github.com/reiddraper/array-binary-encoding, if you'd like to examine before running.


  • hypothesis: 6.29.0
  • Python 3.9.7
@Zac-HD Zac-HD added the bug something is clearly wrong here label Dec 1, 2021
@Zac-HD
Copy link
Member

Zac-HD commented Dec 1, 2021

Thanks for reporting, and a beautiful repro!

This is definitely a bug in Hypothesis, though it looks like a hard one to track down and fix...

@Zac-HD

This comment has been minimized.

@reiddraper

This comment has been minimized.

@Zac-HD
Copy link
Member

Zac-HD commented Dec 30, 2021

Hey @reiddraper - I couldn't get your repro to fail locally, but debugging from the other direction I'm pretty sure that #3203 fixes it - it looks like the problem was that our least-recently-reused cache could drop an entry just before it got pinned, and the inherited pin method assumed that was impossible.

If you could confirm that the fix works for you (or not!), that would be awesome 🙏

@reiddraper
Copy link
Author

Thanks @Zac-HD! I'll try the updated version as soon as I can 🙇.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants