python-jsonschema/hypothesis-jsonschema

Unstable canonicalisation

Zac-HD opened this issue · 2 comments

____________ test_canonicalises_to_equivalent_fixpoint[any-schema] _____________
[gw0] linux -- Python 3.7.10 /home/runner/work/hypothesis-jsonschema/hypothesis-jsonschema/.tox/test/bin/python
tests/test_canonicalise.py:27: in test_canonicalises_to_equivalent_fixpoint
    @given(data=st.data())
tests/test_canonicalise.py:33: in test_canonicalises_to_equivalent_fixpoint
    assert cc == canonicalish(cc)
E   AssertionError: assert {'not': {'min...g', 'object']} == {'type': ['nu...g', 'object']}
E     Omitting 1 identical items, use -vv to show
E     Left contains 1 more item:
E     {'not': {'minItems': 1, 'type': 'array'}}
E     Use -v to get the full diff
---------------------------------- Hypothesis ----------------------------------
Falsifying example: test_canonicalises_to_equivalent_fixpoint(
    data=data(...), schema_strategy=_json_schemata(),
)
Draw 1 (schema): {'not': {'anyOf': [{'type': 'array', 'items': {}, 'contains': {}}, {'type': 'array', 'items': True}]}}

There is a similar canonicalisation issue with not involved:

>>> schema = {"type": "integer", "not": {"required": ["foo"]}}
>>> canonicalish(schema)
{'type': 'integer', 'not': {'type': 'integer'}}
>>> canonicalish(canonicalish(schema))
{'not': {}}

Not sure if it is exactly the same issue, though, but may be related

Yeah, that's a simpler but equivalent problem.

Importantly the canonicalisation is correct if incomplete in both cases, so given the difficulty of fixing it I'm not treating the possible gain in efficiency as a particularly urgent issue.