Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
felipe-cerqueira opened this issue Jul 7, 2022 · 4 comments

Comments

@felipe-cerqueira
Copy link

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.

@dahlia
Copy link
Contributor

dahlia commented Aug 28, 2022

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.

@felipe-cerqueira
Copy link
Author

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

@dahlia
Copy link
Contributor

dahlia commented Sep 2, 2022

Always feel free to send patches. Thanks!

@rafspiny
Copy link

rafspiny commented Mar 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants