Python 如何阻止SqlAlchemy缓存自定义类型表达式?

Python 如何阻止SqlAlchemy缓存自定义类型表达式?,python,sqlalchemy,Python,Sqlalchemy,我们为本地化任务实现了一个自定义类型:我们只需使用带有两个字母语言键的JSONB保存多个语言短语 class LocalizedString(JSONB): def __init__(self): super().__init__() @property def whole_json(self): return not self.locale_id @property def locale_id(self): if threading.current_thread()

我们为本地化任务实现了一个自定义类型:我们只需使用带有两个字母语言键的JSONB保存多个语言短语

class LocalizedString(JSONB):
def __init__(self):
    super().__init__()

@property
def whole_json(self):
    return not self.locale_id

@property
def locale_id(self):
    if threading.current_thread().ident in thread_data:
        return thread_data[threading.current_thread().ident].locale_id
    return 'fa'

def column_expression(self, colexpr):
    if self.whole_json:
        return colexpr
    else:
        return func.delocalized(colexpr, self.locale_id)

def bind_expression(self, bindvalue):
    val = type_coerce(bindvalue, String)
    if self.whole_json:
        return val
    else:
        if hasattr(thread_data.get(threading.current_thread().ident), 'action') and \
                        thread_data[threading.current_thread().ident].action == 'update':
            return func.json_append(Column(bindvalue.key), self.locale_id, func.to_json(cast(val, VARCHAR)))
        else:
            return func.localized(self.locale_id, val)
问题是bind_表达式在第一次使用后只是缓存表达式,但我们尝试从HTTP头设置语言键!我们如何停止SqlAlchemy缓存表达式并强制它为每个查询计算表达式