Vitor-Avila commented on code in PR #37361:
URL: https://github.com/apache/superset/pull/37361#discussion_r2728012229
##########
superset/utils/cache_manager.py:
##########
@@ -27,8 +28,134 @@
CACHE_IMPORT_PATH =
"superset.extensions.metastore_cache.SupersetMetastoreCache"
+# Hash function lookup table matching superset.utils.hashing
+_HASH_METHODS: dict[str, Callable[..., Any]] = {
+ "sha256": hashlib.sha256,
+ "md5": hashlib.md5,
+}
+
+
+class ConfigurableHashMethod:
+ """
+ A callable that defers hash algorithm selection to runtime.
+
+ Flask-caching's memoize decorator evaluates hash_method at decoration time
+ (module import), but we need to read HASH_ALGORITHM config at function call
+ time when the app context is available.
+
+ This class acts like a hashlib function but looks up the configured
+ algorithm when called.
+ """
+
+ def __call__(self, data: bytes = b"") -> Any:
+ """
+ Create a hash object using the configured algorithm.
+
+ Args:
+ data: Optional initial data to hash
+
+ Returns:
+ A hashlib hash object (e.g., sha256 or md5)
+
+ Raises:
+ ValueError: If HASH_ALGORITHM is set to an unsupported value
+ """
+ algorithm = current_app.config["HASH_ALGORITHM"]
Review Comment:
If I got this correctly, users need to have a `HASH_ALGORITHM` defined in
`superset_config.py` or else this will raise, right?
I'm thinking we either need to add a mention to `UPDATING.md` that users
need to define a value, or even better you could add `HASH_ALGORITHM` to the
`config.py` with the default value set to `md5` (to make sure existing cache
keys would still match). What do you think?
##########
superset/utils/cache_manager.py:
##########
@@ -27,8 +28,134 @@
CACHE_IMPORT_PATH =
"superset.extensions.metastore_cache.SupersetMetastoreCache"
+# Hash function lookup table matching superset.utils.hashing
+_HASH_METHODS: dict[str, Callable[..., Any]] = {
+ "sha256": hashlib.sha256,
+ "md5": hashlib.md5,
+}
Review Comment:
If you think my other comment makes sense and you end up working on a new
commit, might make sense to call this `_SUPPORTED_HASH_METHODS`, what do you
think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]