Do not let invalid grammar crash the server (#2023)

This commit is contained in:
Lianmin Zheng
2024-11-13 11:39:16 -08:00
committed by GitHub
parent f407fcf9ef
commit 218ab3611d
3 changed files with 30 additions and 8 deletions
@@ -52,7 +52,7 @@ class BaseGrammarBackend:
else:
entry.value = self.init_value_impl(key)
entry.event.set()
return entry.value.copy()
return entry.value.copy() if entry.value else None
def init_value_impl(self, key: Tuple[str, str]) -> BaseGrammarObject:
raise NotImplementedError()
@@ -62,7 +62,8 @@ class BaseGrammarBackend:
entry = self.cache.get(key)
if not entry or not entry.event.is_set():
return None
return self.cache[key].value.copy()
val = self.cache[key].value
return val.copy() if val else None
def get_future_value(self, key: Tuple[str, str]) -> Future:
return self.executor.submit(self.init_value, key)