json-schema icon indicating copy to clipboard operation
json-schema copied to clipboard

Validator cache doesn't account for list: (true | false) changes

Open leppert opened this issue 9 years ago • 7 comments

If you reference the same schema, first with list: true and then with list: false, the second call will return a cached version of the schema with the array wrapper from list: true. Perhaps the list param should be taken into account when generating the cache key?

leppert avatar Mar 16 '15 16:03 leppert

I just stumbled upon this bug that created random errors in my test suite. I worked around it by clearing the cache after each validation where list is true.

ysbaddaden avatar May 06 '15 07:05 ysbaddaden

I also had this bug, my workaround was to clear the cache for each spec.

JSON::Validator.clear_cache
JSON::Validator.validate!(schema_path, response_body, default_optitons.merge(options))

Of course this hurts performance, and i agree with @leppert that the cache key could be different for list

tegon avatar Jul 13 '15 14:07 tegon

This also bit me. Clearing the cache worked. Caching should definitely take into account list: true.

lleger avatar Aug 26 '15 19:08 lleger

Same here

skoushan avatar Nov 20 '15 20:11 skoushan

Same here, this created random pass/fail effects in my test suite

infiton avatar Jan 26 '16 21:01 infiton

As mentioned, the issue is that when we create an array schema, we modify the original (by wrapping it in a new schema that takes an array of the original - see JSON::Schema.to_array_schema) but then when we store it in the cache we use the uri of the original schema (see JSON::Validator.add_schema). If we modify the schema at all we should also give it a new uri, to ensure that it doesn't cause a cache collision with the original.

iainbeeston avatar Jan 27 '16 08:01 iainbeeston

This new URI has to be deterministic, we cannot just generate a UUID (which was my first thought) or revalidation will fail again for basically the same reason.

RST-J avatar Jan 27 '16 18:01 RST-J