You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When jsonschema is used with pypy and the schema used contains a oneOf rule, the memory consumption grows indefinitely over time. This only seems to happen if there is a matching subschema, but it's not the last subschema in the oneOf list. This only happens in pypy:
importjsonimportjsonschemawithopen("schema.json", encoding='utf-8') asschema_file:
schema=jsonschema.Draft4Validator(json.loads(schema_file.read()))
obj= {'field': 3} # matches first subschema - causes a leak# obj = {'field': True} # matches last subschema - does not cause a leakforjinrange(0, 1000000):
schema.is_valid(obj)
Running this in pypy quickly shows the memory consumption going up to a few gigabytes.
This might be a pypy bug, but I was not able to re-create this leak without the use of jsonschema.
If it helps, as a workaround I use modified jsonschema with this is_valid function in jsonschema/validators.py:
def is_valid(self, instance, _schema=None):
# Fully iterate through the generator to avoid a pypy memory leak
errors = list(self.iter_errors(instance, _schema))
return not errors
The text was updated successfully, but these errors were encountered:
When jsonschema is used with pypy and the schema used contains a oneOf rule, the memory consumption grows indefinitely over time. This only seems to happen if there is a matching subschema, but it's not the last subschema in the oneOf list. This only happens in pypy:
See the code and json schema below (
schema.json
):Running this in pypy quickly shows the memory consumption going up to a few gigabytes.
This might be a pypy bug, but I was not able to re-create this leak without the use of jsonschema.
If it helps, as a workaround I use modified jsonschema with this
is_valid
function injsonschema/validators.py
:The text was updated successfully, but these errors were encountered: