aminghadersohi commented on code in PR #37361:
URL: https://github.com/apache/superset/pull/37361#discussion_r2719728689
##########
superset/utils/cache_manager.py:
##########
@@ -27,8 +28,129 @@
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)
+ """
+ algorithm = current_app.config["HASH_ALGORITHM"]
+ hash_func = _HASH_METHODS[algorithm]
+ return hash_func(data)
Review Comment:
This will raise a bare KeyError if HASH_ALGORITHM is set to an unsupported
value. Consider matching the pattern in hashing.py which uses .get() and raises
a ValueError with a descriptive message:
```
algorithm = current_app.config["HASH_ALGORITHM"]
hash_func = _HASH_METHODS.get(algorithm)
if hash_func is None:
raise ValueError(f"Unsupported hash algorithm: {algorithm}")
return hash_func(data)
```
--
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]