Skip to content

Commit da90228

Browse files
authored
Chore: put a lock around the lazy dialect module loading call (#5011)
1 parent 7ffea3c commit da90228

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sqlglot/dialects/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Generator(Generator):
6262
"""
6363

6464
import importlib
65+
import threading
6566

6667
DIALECTS = [
6768
"Athena",
@@ -104,11 +105,14 @@ class Generator(Generator):
104105

105106
__all__ = list(MODULE_BY_ATTRIBUTE)
106107

108+
_import_lock = threading.Lock()
109+
107110

108111
def __getattr__(name):
109112
module_name = MODULE_BY_ATTRIBUTE.get(name)
110113
if module_name:
111-
module = importlib.import_module(f"sqlglot.dialects.{module_name}")
114+
with _import_lock:
115+
module = importlib.import_module(f"sqlglot.dialects.{module_name}")
112116
return getattr(module, name)
113117

114118
raise AttributeError(f"module {__name__} has no attribute {name}")

0 commit comments

Comments
 (0)