]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
generalize cache_ok to UserDefinedType
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Nov 2021 20:08:29 +0000 (15:08 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Nov 2021 20:55:21 +0000 (15:55 -0500)
commit77f987022c0768a553be1f052c735c0bf3428aa1
tree0ac598f715fc035d4b60e3342d040f17a81e4b37
parent24a53fd8fce2cdfb0154caa687ef893bcff120a7
generalize cache_ok to UserDefinedType

Extended the ``cache_ok`` flag and corresponding warning message if this
flag is not defined, a behavior first established for
:class:`.TypeDecorator` as part of :ticket:`6436`, to also take place for
:class:`.UserDefinedType`, by generalizing the flag and associated caching
logic to a new common base for these two types, :class:`.ExternalType`.

The change means any current :class:`.UserDefinedType` will now cause SQL
statement caching to no longer take place for statements which make use of
the datatype, along with a warning being emitted, unless the class defines
the :attr:`.UserDefinedType.cache_ok` flag as True. If the datatype cannot
form a deterministic, hashable cache key derived from its arguments, it may return
False which will continue to keep caching disabled but will suppress the
warning. In particular, custom datatypes currently used in packages such as
SQLAlchemy-utils will need to implement this flag. The issue was observed
as a result of a SQLAlchemy-utils datatype that is not currently cacheable.

Fixes: #7319
Change-Id: Ie0b5d4587df87bfe66d2fe7cd4585c3882584575
(cherry picked from commit 4761e6878b127f7d5fb09addaae15426edbb0b73)
doc/build/changelog/unreleased_14/7319.rst [new file with mode: 0644]
doc/build/core/custom_types.rst
doc/build/core/type_api.rst
lib/sqlalchemy/sql/type_api.py
lib/sqlalchemy/types.py
test/sql/test_compare.py
test/sql/test_types.py