Set cache_ok to avoid SAWarning

Since sqlalchemy 1.4.14[1], the following warning is raised unless
the cache_ok flag is explicitly set in classes inheriting
TypeDecorator.

SAWarning: TypeDecorator Json() will not produce a cache key because
the ``cache_ok`` attribute is not set to True.  This can have
significant performance implications including some performance
degradations in comparison to prior SQLAlchemy versions.
Set this attribute to True if this type object's state is safe to use
in a cache key, or False to disable this warning. (Background on this
error at: https://sqlalche.me/e/14/cprf)

Because the flag was set to True by default in older releases, this
adds explicit cache_ok = True, to restore the previous behavior in
Wallaby and older. (wallaby u-c has SQLAlchemy===1.3.23 while xena u-c
has SQLAlchemy===1.4.23)

[1] 6967b45020

Change-Id: I6b84a626994543468f49373a554de44025576a9a
This commit is contained in:
Takashi Kajinami 2022-06-15 10:31:53 +09:00
parent 27f7a81650
commit 14d2d859ef
1 changed files with 2 additions and 0 deletions

View File

@ -23,6 +23,7 @@ loads = jsonutils.loads
class LongText(types.TypeDecorator):
impl = types.Text
cache_ok = True
def load_dialect_impl(self, dialect):
if dialect.name == 'mysql':
@ -45,6 +46,7 @@ class Json(LongText):
class List(types.TypeDecorator):
impl = types.Text
cache_ok = True
def load_dialect_impl(self, dialect):
if dialect.name == 'mysql':