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

Doesn't have cache_ok = True which can have significant performance implications

Open felipe-cerqueira opened this issue 3 years ago • 4 comments

While using sqlalchemy_enum34 I've seen the following error message: SAWarning: TypeDecorator Enum('CREATED', 'RETRY', 'EXPIRED', 'FINISHED') 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)

Apparently, only adding cache_ok = True would solve the problem.

felipe-cerqueira avatar Jul 07 '22 18:07 felipe-cerqueira

sqlalchemy_enum34.EnumType() can take every options that sqlalchemy.types.Enum() can take. Therefore, you just can add cache_ok=True to sqlalchemy_enum34.EnumType() and it will suppress the warning.

dahlia avatar Aug 28 '22 05:08 dahlia

That's right. Would you mind if I send a PR including that? Thank you

felipe-cerqueira avatar Sep 01 '22 19:09 felipe-cerqueira

Always feel free to send patches. Thanks!

dahlia avatar Sep 02 '22 08:09 dahlia

Hi all,

I tried to overcome this and just passing it do not work.

my_field = db.Column(EnumType(<class_name>, cache_ok=False), nullable=False)

I had to extend EnumType (well, Enum) and add cache_ok there.

from sqlalchemy_enum34 import EnumType
class EnumWithCache(EnumType):
    cache_ok = False

Not sure what would be your preferred way of proceeding here. Or maybe I misinterpreted what you said about the options that sqlalchemy_enum34.Enum can take

rafspiny avatar Mar 03 '23 12:03 rafspiny