Fix flaky errors with py3 #201
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We ran into some test failures while using
jsonschema==2.4.0
with python3. The failures were intermittent (approximately 1 in every 10 runs), but were reproducible in both py33 and py34 (py26 and py27 were unaffected).You can see the failures in travis-ci for this PR Yelp/swagger_spec_validator#11 or use that branch to reproduce them (
tox -e py34
). The best example istest_success
in this build.The code calling
jsonschema
is pretty straightforward:The error is:
I added a bunch of debugging to
jsonschema
to see what was happening. From what I can tell,RefResolver.resolve_fragment()
is being called with a ref ofdefinitions/simpleTypes
but the current base_uri in theRefResolver
is actuallyhttp://swagger.io/v2/schema.json
instead of what it should be (http://json-schema.org/draft-04/schema
).I also noticed that the ordering was totally undefined, every run would produce a different call stack. Some orderings would fail, and some would succeed, but there was definitely more than one order which caused it to fail. I tried a few things, and found that adding this
sorted()
to iterations beforedescend()
resolved the problem. I tried withlist()
as well, but that didn't solve the problem.Without being able to completely explain the problem, I can say that this fixes it. My understanding is that some combination of the undefined order of fields, and the lazy evaluation of
iteritems()
causes some call stack which results in the wrong state.