bito-code-review[bot] commented on code in PR #37361:
URL: https://github.com/apache/superset/pull/37361#discussion_r2720819293


##########
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"]
+        hash_func = _HASH_METHODS.get(algorithm)
+        if hash_func is None:
+            raise ValueError(f"Unsupported hash algorithm: {algorithm}")

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing test coverage for error case</b></div>
   <div id="fix">
   
   The change adds error handling for unsupported hash algorithms, but tests 
should verify this behavior to prevent regressions. Consider adding a test case 
that sets an invalid algorithm and checks for ValueError.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #3323b0</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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]

Reply via email to