From 1dc20f646b558354e4ba434f4132a1b7979d563e Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 22 Jun 2021 11:54:01 +0100 Subject: [PATCH] types: Set 'cache_ok' Resolves the following warning that has been popping up on tests: SAWarning: TypeDecorator SoftDeleteInteger() will not produce a cache key because the ``cache_ok`` flag is not set to True. Set this flag to True if this type object's state is safe to use in a cache key, or False to disable this warning. Both SoftDeleteInteger and the various subclasses of 'JsonEncodedType' are hashable and should return a consistent hash and key. For more information, refer to the SQLAlchemy docs [1]. [1] https://docs.sqlalchemy.org/en/14/core/custom_types.html#sqlalchemy.types.TypeDecorator.cache_ok Change-Id: Idf6fd858fad9521c7c5ba82c31b6d3077756abd9 Signed-off-by: Stephen Finucane --- oslo_db/sqlalchemy/types.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/oslo_db/sqlalchemy/types.py b/oslo_db/sqlalchemy/types.py index 08b1f2b2..d4d90699 100644 --- a/oslo_db/sqlalchemy/types.py +++ b/oslo_db/sqlalchemy/types.py @@ -21,6 +21,8 @@ class JsonEncodedType(TypeDecorator): type = None impl = Text + cache_ok = True + """This type is safe to cache.""" def __init__(self, mysql_as_long=False, mysql_as_medium=False): """Initialize JSON-encoding type.""" @@ -101,6 +103,8 @@ class SoftDeleteInteger(TypeDecorator): """ impl = Integer + cache_ok = True + """This type is safe to cache.""" def process_bind_param(self, value, dialect): """Return the binding parameter."""