File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ Bug Fixes
3535::
3636
3737 * Add python version requirement on setup.py (#586) [jason-the-j]
38+ * Add a thread lock to avoid concurrent schema construction. (#545) [peter-doggart]
3839 * Fix Nested field schema generation for nullable fields. (#638) [peter-doggart]
3940 * Fix reference resolution for definitions in schema. (#553) [peter-doggart]
4041
Original file line number Diff line number Diff line change 22import inspect
33from itertools import chain
44import logging
5+ import threading
56import operator
67import re
78import sys
@@ -161,6 +162,7 @@ def __init__(
161162 }
162163 )
163164 self ._schema = None
165+ self ._schema_lock = threading .Lock ()
164166 self .models = {}
165167 self ._refresolver = None
166168 self .format_checker = format_checker
@@ -567,14 +569,17 @@ def __schema__(self):
567569 :returns dict: the schema as a serializable dict
568570 """
569571 if not self ._schema :
570- try :
571- self ._schema = Swagger (self ).as_dict ()
572- except Exception :
573- # Log the source exception for debugging purpose
574- # and return an error message
575- msg = "Unable to render schema"
576- log .exception (msg ) # This will provide a full traceback
577- return {"error" : msg }
572+ # Guard schema initialization to avoid concurrent construction on first access
573+ with self ._schema_lock :
574+ if not self ._schema :
575+ try :
576+ self ._schema = Swagger (self ).as_dict ()
577+ except Exception :
578+ # Log the source exception for debugging purpose
579+ # and return an error message
580+ msg = "Unable to render schema"
581+ log .exception (msg ) # This will provide a full traceback
582+ return {"error" : msg }
578583 return self ._schema
579584
580585 @property
You can’t perform that action at this time.
0 commit comments