sqlalchemy-citext icon indicating copy to clipboard operation
sqlalchemy-citext copied to clipboard

SAWarning in cache key for CIText()

Open miketheman opened this issue 3 years ago • 5 comments

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.

miketheman avatar Jan 02 '22 23:01 miketheman

Same issue. So is it ok to tell SQLAlchemy cache_ok=True?

HansBouwmeester avatar Apr 07 '22 02:04 HansBouwmeester

@Gra55h0pper my understanding is that since this is a stateless type definition then we are good to set cache_ok = True

TimelyToga avatar Apr 18 '22 18:04 TimelyToga

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

evrys avatar Jun 01 '22 02:06 evrys

Will take a look and push it out in 24 hours if it works. Thanks for the PR.

mahmoudimus avatar Jun 01 '22 02:06 mahmoudimus

https://github.com/mahmoudimus/sqlalchemy-citext/pull/28

rouge8 avatar Jun 02 '22 16:06 rouge8