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]06f031e55f/lib/sqlalchemy/sql/type_api.py (L1048-L1050)
[2]06f031e55f/lib/sqlalchemy/sql/type_api.py (L979-L983)
Closes-Bug: #1927763 Change-Id: I67b7cf6c4a0a269c1d0c91ed1265d36208f67cef
This commit is contained in:
parent
65df195563
commit
cb2dd61ac4
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user