Skip to content

Commit 1fa3ebc

Browse files
committed
Use store argument for RefResolver as if it was mandatory
This is necessary to avoid problems with recompilation and caching of schemas.
1 parent c4b6076 commit 1fa3ebc

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

fastjsonschema/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def compile_to_code(definition, handlers={}, formats={}, use_default=True):
213213

214214

215215
def _factory(definition, handlers, formats={}, use_default=True):
216-
resolver = RefResolver.from_schema(definition, handlers=handlers)
216+
resolver = RefResolver.from_schema(definition, handlers=handlers, store={})
217217
code_generator = _get_code_generator_class(definition)(
218218
definition,
219219
resolver=resolver,

fastjsonschema/generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, definition, resolver=None):
5454
self._validation_functions_done = set()
5555

5656
if resolver is None:
57-
resolver = RefResolver.from_schema(definition)
57+
resolver = RefResolver.from_schema(definition, store={})
5858
self._resolver = resolver
5959

6060
# add main function to `self._needed_validation_functions`

fastjsonschema/ref_resolver.py

+7
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,19 @@ class RefResolver:
7777
def __init__(self, base_uri, schema, store={}, cache=True, handlers={}):
7878
"""
7979
`base_uri` is URI of the referring document from the `schema`.
80+
`store` is an dictionary that will be used to cache the fetched schemas
81+
(if `cache=True`).
82+
83+
Please notice that you can have caching problems when compiling schemas
84+
with colliding `$ref`. To force overwriting use `cache=False` or
85+
explicitly pass the `store` argument (with a brand new dictionary)
8086
"""
8187
self.base_uri = base_uri
8288
self.resolution_scope = base_uri
8389
self.schema = schema
8490
self.store = store
8591
self.cache = cache
92+
# ^-- Create a brand new cache if the
8693
self.handlers = handlers
8794
self.walk(schema)
8895

0 commit comments

Comments
 (0)