sqlalchemy-citext
sqlalchemy-citext copied to clipboard
SAWarning in cache key for CIText()
Observed using SQLAlchmey 1.4.28 and sqlalchemy-citext 1.8
SAWarning: UserDefinedType CIText() 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)
Introduced in SQLAlchemy https://github.com/sqlalchemy/sqlalchemy/commit/22deafe15289d2be55682e1632016004b02b62c0
I'm not entirely certain how this would affect behaviors, but wanted to surface this.
Same issue. So is it ok to tell SQLAlchemy cache_ok=True
?
@Gra55h0pper my understanding is that since this is a stateless type definition then we are good to set cache_ok = True
Sent a PR to add cache_ok = True
, in meantime can work around it by extending the class like so
class CacheyCIText(CIText):
# Workaround for https://github.com/mahmoudimus/sqlalchemy-citext/issues/25
# Can remove when that issue is fixed
cache_ok = True
Will take a look and push it out in 24 hours if it works. Thanks for the PR.
https://github.com/mahmoudimus/sqlalchemy-citext/pull/28