From cb2dd61ac492df4ab9f0e4ea6f89c6ea3f138ccd Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Fri, 3 Sep 2021 15:45:05 +0000 Subject: [PATCH] Set "cache_ok=True" in all "TypeDecorator" derived classes The requirement for cacheable elements is that they are haseable [1]. "IPAddress", "CIDR" and "MACAddress" "impl" attribute [2] is type "String". "TruncatedDateTime" "impl" attribute is type "DateTime". All of them are hasheable: >>> from sqlalchemy import types >>> impl = types.DateTime() >>> impl.hashable True >>> impl = types.String(64) >>> impl.hashable True [1]https://github.com/zzzeek/sqlalchemy/blob/06f031e55f40403996e3580bdc5a22661b6303f4/lib/sqlalchemy/sql/type_api.py#L1048-L1050 [2]https://github.com/zzzeek/sqlalchemy/blob/06f031e55f40403996e3580bdc5a22661b6303f4/lib/sqlalchemy/sql/type_api.py#L979-L983 Closes-Bug: #1927763 Change-Id: I67b7cf6c4a0a269c1d0c91ed1265d36208f67cef --- neutron_lib/db/sqlalchemytypes.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/neutron_lib/db/sqlalchemytypes.py b/neutron_lib/db/sqlalchemytypes.py index 39cb20cb1..79c9a4882 100644 --- a/neutron_lib/db/sqlalchemytypes.py +++ b/neutron_lib/db/sqlalchemytypes.py @@ -22,6 +22,8 @@ class IPAddress(types.TypeDecorator): impl = types.String(64) + cache_ok = True + def process_result_value(self, value, dialect): return netaddr.IPAddress(value) @@ -39,6 +41,8 @@ class CIDR(types.TypeDecorator): impl = types.String(64) + cache_ok = True + def process_result_value(self, value, dialect): return netaddr.IPNetwork(value) @@ -55,6 +59,8 @@ class MACAddress(types.TypeDecorator): impl = types.String(64) + cache_ok = True + def process_result_value(self, value, dialect): return netaddr.EUI(value) @@ -77,7 +83,7 @@ class TruncatedDateTime(types.TypeDecorator): impl = types.DateTime - cache_ok = False + cache_ok = True def process_bind_param(self, value, dialect): return value.replace(microsecond=0) if value else value